nakst/gf

Cannot add breakpoint on future shared library

omcaif opened this issue · 3 comments

omcaif commented

When trying to add a breakpoint on a file from a shared library which has not yet been loaded, GDB prompts a y or [n] to make a pending breakpoint on future shared library. The result in gf is always [answered N; input not from terminal] and not making a breakpoint.

A similar situation occurs when sending kill into GDB except I get a GUI prompt to kill or cancel.

"Dumb" example to illustrate the problem:

main.c:

#include <dlfcn.h>

typedef void FooFunc(void *data);

int main(void)
{
	void *foo_lib = dlopen("./libfoo.so", RTLD_NOW);

	FooFunc *foo_func = dlsym(foo_lib, "foo_func");
	char foo_data[1024] = {0};

	for (int i = 0; i < 5; ++i) {
		foo_func(foo_data);
	}

	dlclose(foo_lib);
}

foo.c:

struct Bar {
	int state;
	int the_variable;
};

void foo_func(void *data)
{
	struct Bar *bar = data;

	if (bar->state == 0) {
		bar->state = 1;

		bar->the_variable = 37;
	}

	++bar->the_variable;
}

build:

#!/bin/sh

gcc -ggdb -shared foo.c -o libfoo.so
gcc -ggdb main.c

Try, for example, to break on foo.c:10 before calling dlopen().

nakst commented

Does running the GDB command set breakpoint pending on first make a difference?

omcaif commented

Yes. That works as a workaround. Thanks.

nakst commented

Commit 29ed990 includes instructions in the README file for this.