Saggy Posted January 16, 2009 Share Posted January 16, 2009 I'm trying to debug a function that is in another source file than main.c, called init.c, how can I instruct gdb to add a breakpoint at line 15 of a function in init.c named init()? QUOTE (K^2) ...not only is it legal for you to go around with a concealed penis, it requires absolutely no registration! Link to comment Share on other sites More sharing options...
K^2 Posted January 16, 2009 Share Posted January 16, 2009 I don't know about GDB, but you can always trace it manually in the debugger. The source file doesn't matter. You just need to know when a function that interests you is getting called. Then you can find the line you want by reading through ASM code yourself (15 lines of C to ASM isn't all that much) or you can put a call to a useless function that would be easy to recognize. Most debuggers will recognize a call to a standard function like printf. Prior to filing a bug against any of my code, please consider this response to common concerns. Link to comment Share on other sites More sharing options...
Saggy Posted January 16, 2009 Author Share Posted January 16, 2009 I don't know about GDB, but you can always trace it manually in the debugger. The source file doesn't matter. You just need to know when a function that interests you is getting called. Then you can find the line you want by reading through ASM code yourself (15 lines of C to ASM isn't all that much) or you can put a call to a useless function that would be easy to recognize. Most debuggers will recognize a call to a standard function like printf. I actually use to do it similar to that, but from time to time I'd find that some part of the code that happened later in the text, happened before-hand in the machine code for some reason, which is when I started using gdb. I really can't cite a specific example, but it happened once or twice. In any case, your mention of debuggers reocngize calls to standard functions... It just so happens gdb can add a breakpoint to a function name, so I just did b init and after that I could do b line_number for whatever line it was in the function I needed to stop on. Finished the program too, and then realized I could do what I wanted with *nix's "sort" command with "sort -R". Oh well, at least I got some practice programming, figured out how to do something I've been meaning to for a while. QUOTE (K^2) ...not only is it legal for you to go around with a concealed penis, it requires absolutely no registration! Link to comment Share on other sites More sharing options...
K^2 Posted January 16, 2009 Share Posted January 16, 2009 The order of operations can be switched some times, but the order of lines cannot be. If you put a call to known function before the line that interests you, code for that line will always immediately follow the call. Prior to filing a bug against any of my code, please consider this response to common concerns. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now