LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-14-2012, 06:30 PM   #1
maxreason
Member
 
Registered: Dec 2007
Location: phobos, mars
Distribution: 64-bit linux mint v20
Posts: 259

Rep: Reputation: 17
can gdb step into static library ?


When I am debugging my program that is linked to a shared library, I'm guessing gdb can't (or won't) let me step into code in the library, correct? If it did, it would risk other applications hitting the breakpoint it set, which would be a super-no-no.

However, is there any reason gdb can't (or won't) let me step into code in a static library linked into my program?

What would I need to make that happen? I'm debugging with codeblocks, and it doesn't let me step into functions being called.
 
Old 07-14-2012, 06:37 PM   #2
dwhitney67
Senior Member
 
Registered: Jun 2006
Location: Maryland
Distribution: Kubuntu, Fedora, RHEL
Posts: 1,541

Rep: Reputation: 335Reputation: 335Reputation: 335Reputation: 335
Quote:
Originally Posted by maxreason View Post
When I am debugging my program that is linked to a shared library, I'm guessing gdb can't (or won't) let me step into code in the library, correct? If it did, it would risk other applications hitting the breakpoint it set, which would be a super-no-no.

However, is there any reason gdb can't (or won't) let me step into code in a static library linked into my program?

What would I need to make that happen? I'm debugging with codeblocks, and it doesn't let me step into functions being called.
Both of your assumptions are incorrect. You can step into a shared-object library when debugging, and equally do the same with a static-library. The only caveat is that these libraries must be compiled with symbolic information; typically this is done by using the -g compiler option when compiling each source file.
 
3 members found this post helpful.
Old 07-14-2012, 08:55 PM   #3
maxreason
Member
 
Registered: Dec 2007
Location: phobos, mars
Distribution: 64-bit linux mint v20
Posts: 259

Original Poster
Rep: Reputation: 17
Quote:
Originally Posted by dwhitney67 View Post
Both of your assumptions are incorrect. You can step into a shared-object library when debugging, and equally do the same with a static-library. The only caveat is that these libraries must be compiled with symbolic information; typically this is done by using the -g compiler option when compiling each source file.
Why would it need symbols to single-step? I don't know how the library was compiled, but objdump displays all sorts of symbols, so that should be enough for gdb.

So I guess the question is, how can I make gdb step into the library?
 
Old 07-14-2012, 11:21 PM   #4
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,862
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
Use option -g at compilation and linkage.
 
1 members found this post helpful.
Old 07-15-2012, 03:09 AM   #5
knudfl
LQ 5k Club
 
Registered: Jan 2008
Location: Copenhagen DK
Distribution: PCLinuxOS2023 Fedora38 + 50+ other Linux OS, for test only.
Posts: 17,511

Rep: Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641
Quote:
but objdump displays all sorts of symbols, so that should be enough for gdb
'objdump' will show all objects (symbols ?).

It's the symbol information which is usually missing.

.
 
Old 07-15-2012, 07:43 AM   #6
gchen
Member
 
Registered: May 2012
Location: Beijing China
Distribution: Asianux
Posts: 56

Rep: Reputation: Disabled
Smile

Firstly, -g means all symbols (source code level);

if no -g (and not strip), gcc will generate the symbols for none-inline functions and global variables (although, it is not source code level, but truly usful).


you can step into every shared library and static library with disassembly code (use m command, maybe it is, you can reference the gcc help command to know it).

if no -g (and not strip), you can see the relative none-inline function name and relative global variables. (you can use "disassemble" command, to disassemble the none-inline functions)

if have -g, you can see all things (with source code level).

if no -g and the binary executable are stripped, it is truly no symbols at all, but you still can step into the shared library and static library (but without symbols).


: )
 
1 members found this post helpful.
Old 07-15-2012, 04:16 PM   #7
maxreason
Member
 
Registered: Dec 2007
Location: phobos, mars
Distribution: 64-bit linux mint v20
Posts: 259

Original Poster
Rep: Reputation: 17
gchen: Thanks for the thorough information.

I guess this means that when I click "step-into" icon in codeblocks, they aren't executing the appropriate "step-into" in gdb (which is the adopted debugger).

And yes, as you say, the debugger clearly understands where assembly/machine-language instruction boundaries are (without symbols), otherwise it couldn't single step in assembly-language at all, which it does. And, of course, gdb couldn't execute the "disassemble" command, which it does.

My "off the cuff" guess was... shared libraries wouldn't work because they were configured as "read/execute-only" in memory (since other executables might be running the library, any breakpoint instructions stuck in the code would be a disaster). But I didn't see why static-linked would be any more protected than the original program, since they are all built into one executable.

I still don't have a definitive answer, but I'll go ask the guys at codeblocks what they do when someone tries to "step into" at a line that calls a function inside a static-linked library.

Thanks for the info about gdb.
 
Old 07-15-2012, 07:04 PM   #8
gchen
Member
 
Registered: May 2012
Location: Beijing China
Distribution: Asianux
Posts: 56

Rep: Reputation: Disabled
Smile

Quote:
Originally Posted by maxreason View Post
gchen: Thanks for the thorough information.

I guess this means that when I click "step-into" icon in codeblocks, they aren't executing the appropriate "step-into" in gdb (which is the adopted debugger).

And yes, as you say, the debugger clearly understands where assembly/machine-language instruction boundaries are (without symbols), otherwise it couldn't single step in assembly-language at all, which it does. And, of course, gdb couldn't execute the "disassemble" command, which it does.

My "off the cuff" guess was... shared libraries wouldn't work because they were configured as "read/execute-only" in memory (since other executables might be running the library, any breakpoint instructions stuck in the code would be a disaster). But I didn't see why static-linked would be any more protected than the original program, since they are all built into one executable.

I still don't have a definitive answer, but I'll go ask the guys at codeblocks what they do when someone tries to "step into" at a line that calls a function inside a static-linked library.

Thanks for the info about gdb.

1) The debugger will use "write copy" ways to solve the "read/execute-only" segements issue. So we can still step into shared library.

2) For shared memory (or filemap) (data segment, no read priority), the original gdb version can not access it (but maybe current gdb can do).

3) For GUI debugger, if no "-g", for step-into, default is failed (but after simply configured, it can step-into by showing disassembly code).

4) For different GUI debugger (or IDE), the configurations are different, but I am sure that they all include the features what I said above.

5) If you truly want see source code, commonly, you have to compile the shared library and static library with "-g" option (for Red Hat, it has another way to solve it).


I hope these information above might be usefull for you.


: )
 
1 members found this post helpful.
Old 07-16-2012, 02:33 AM   #9
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239
you can use gdb standalone you know.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Gdb did not step into function when "step" typed!!! 915086731 Programming 4 06-23-2010 09:44 AM
unable to step through function in shared object library using gdb markhod Programming 2 01-03-2009 02:00 AM
creating static library that includes another static library kskkumar Programming 2 10-22-2007 10:51 AM
howto compile bin with my library using all-static and shared linked standart library stpg Programming 4 06-29-2004 04:20 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:18 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration