gcc -g :what will happen

That’s kind of right, but incomplete. -g requests that the compiler and linker generate and retain source-level debugging/symbol information in the executable itself. If… the program happens to later crash and produce a core file (which suggests some problem in the actual code), or a deliberate OS command forced it to core (e.g. kill -SIGQUIT pid), or the program … Read more

Is there an “until” command in gdb?

In addition to Michael’s explanation of breakpoints, that are probably the best way to solve your problem, there are actually also are “until” and “advance” commands, that do just what you require/suggest. Basically you can do “until 60” or “until main.c:60” or “advance 60” or similar, depending if you want to limit temporary breakpoint to … Read more

How can one see content of stack with GDB?

info frame to show the stack frame info To read the memory at given addresses you should take a look at x x/x $esp for hex x/d $esp for signed x/u $esp for unsigned etc. x uses the format syntax, you could also take a look at the current instruction via x/i $eip etc.

Step out of current function with GDB

You can use the finish command. finish: Continue running until just after function in the selected stack frame returns. Print the returned value (if any). This command can be abbreviated as fin. (See 5.2 Continuing and Stepping.)

Core dump file analysis

You just need a binary (with debugging symbols included) that is identical to the one that generated the core dump file. Then you can run gdb path/to/the/binary path/to/the/core/dump/file to debug it. When it starts up, you can use bt (for backtrace) to get a stack trace from the time of the crash. In the backtrace, each function invocation is … Read more