Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gdb: breakpoints with dynamic library #74

Open
qqldd opened this issue Apr 18, 2019 · 3 comments

Comments

Projects
None yet
2 participants
@qqldd
Copy link

commented Apr 18, 2019

With dynamic library saying, I have:

library.cc -> library.so
main.cc -> main [which use the library.so]

If I dap-add-breakpoint on library.cc:58 on gdb main, the gdb will prompt:

No source file named library.cc
Make breakpoint pending on future shared library load? (y or [n]) 

But dap will ignore with no breakpoint set. So I cannot step into program. Is there any template argument I can configure with?

Usually when I do gdb, I will enter start command to start the program so that the .so file is loaded. I can break on library.cc:58.
Or we can answer yes to: "Make breakpoint pending on future shared library load? (y or [n]) "

@yyoncho

This comment has been minimized.

Copy link
Member

commented Apr 19, 2019

@qqldd I do not have gdb/lldb expertize, so in order to work on this issue I will need detailed steps to reproduce(e. g. how to build shared lib, etc). As far as I can see from Native Debug readme there are some limitations related to setting breakpoints when using gdb(e. g. you should stop the thread and then set the breakpoint) which is a pretty severe limitation and might be related to the problem. The full list of configuration settings could be found here - https://github.com/WebFreak001/code-debug/blob/master/package.json and I don't see a setting related to your problem.

PS: We might try to integrate with the gdb dap adapter implemented by MS which I suspect which be more functional(https://marketplace.visualstudio.com/items?itemName=ms-vscode.cpptools).

@qqldd

This comment has been minimized.

Copy link
Author

commented Apr 20, 2019

Hmm after I write below down, I cannot reproduce this issue using following example even with same output as I describe above. The breakpoints actually useful. I will still keep following for now:

I will modify the command from here to provide instructions on how to create dynamic library: https://www.cprogramming.com/tutorial/shared-libraries-linux-gcc.html

  1. Write foo.c and main.c with following content:
    foo.c:
#include <stdio.h>
void foo(void) {
  puts("Hello, I'm a shared library");
}

main.c:

#include <stdio.h>
extern void foo(void);
int main(void) {
  puts("This is a shared library test...");
  foo();
  return 0;
}

Put foo.c and main.c in same folder and execute following comment in shell:

gcc -c -g -Wall -Werror -fpic foo.c
gcc -g -shared -o libfoo.so foo.o
gcc -L./ -g -Wall -Wl,-rpath $PWD -o test main.c -lfoo

It will output test executable and libfoo.so. libfoo.so is a dynamic library. test will load this library when running.

After that, if I do:
gdb ./test
inside gdb, I type:
(gdb) b foo.c:3 No source file named foo.c. Make breakpoint pending on future shared library load? (y or [n])

But this is not the case after program is running since libfoo.so is loaded:

(gdb) start
Temporary breakpoint 1 at 0x77e: file main.c, line 4.
Starting program: /home/myrice/Work/test 

Temporary breakpoint 1, main () at main.c:4
4         puts("This is a shared library test...");
(gdb) b foo.c:3
Breakpoint 2 at 0x7ffff7bd760e: file foo.c, line 3.

In Eamcs, if I setup a breakpoint at foo.c:3, it will outputs

Unable to determine compiler version.
Skipping loading of libstdc++ pretty-printers for now.
No source file named /home/myrice/Work/foo.c.
Running executable

Breakpoint 1, foo () at foo.c:3
3	  puts("Hello, I'm a shared library");

Yes, it stops. Lol...

I need to see why the complicate one not is not stopping.

@yyoncho

This comment has been minimized.

Copy link
Member

commented Apr 20, 2019

@qqldd did you try to stop the thread after your library is loaded and then place the breakpoint?

Anyway, I think that cpptools gdb adapter will solve your issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.