Mario Gil
Mario Gil

Reputation: 563

How to debug inside a library?

I am coding a program that will have a ncurses TUI, in one function i use the werase(WINDOW * win) function that is causing problems. The function does not return ERR or OK because is causing a segmentation fault in it. What i want to know is how do i see whats going on inside the function declaration. I'm using gdb and enabled set step-mode onand managed to enter the library pressing s over werase, but, gdb outputs something like this:

0x00007ffff7b8fc4b in werase () from /usr/lib/libncursesw.so.5

(gdb)

Then, after a few s keystrokes:

Program received signal SIGSEGV, Segmentation fault.
0x00007ffff7b8fc60 in werase () from /usr/lib/libncursesw.so.5

(gdb)

How do i make gdb to output the line that is reading in the function declaration instead of just de memory address of that line?

Additional information

(gdb) info sharedlibrary
From                To                  Syms Read   Shared Object Library
0x00007ffff7ddbb80  0x00007ffff7df52f0  Yes (*)     /lib64/ld-linux-x86-64.so.2
0x00007ffff7b8b000  0x00007ffff7bbff38  Yes (*)     /usr/lib/libncursesw.so.5
0x00007ffff77f24d0  0x00007ffff791eee4  Yes (*)     /usr/lib/libc.so.6
(*): Shared library is missing debugging information.
(gdb) sharedlibrary libncursesw
Symbols already loaded for /usr/lib/libncursesw.so.5

I found that i had to compile with -lncurses_g or -lcurses_g wich i done already with no result else than /usr/bin/ld: cannot find -lcurses_g. It seems that the debugging info is not installed in my system but i can't figure out why. I'm using Arch linux.

Upvotes: 0

Views: 242

Answers (1)

Moldova
Moldova

Reputation: 1651

Most likely the library is not at fault and you are passing it bad data such as an already freed pointer or a pointer to memory that has been overwritten. Try running your program under valgrind and see if that tells you where the error is.

If you must debug into the library, ncurses is open source so you can download and build it yourself from source with debug on, and link against your own copy. This will give you full source-level debugging in the library.

Upvotes: 1

Related Questions