Yogeshwer Sharma
Yogeshwer Sharma

Reputation: 3837

How to see which line of code "next" would execute in gdb?

While debugging some code in gdb, I want to see which line will be executed if I say next or step.

I am wondering if I am missing a simple command in gdb which shows me the current line the debugger is stopped at?

Upvotes: 4

Views: 6436

Answers (4)

ks1322
ks1322

Reputation: 35708

To see the current line the debugger stopped at, you can use frame command with no arguments. This achieves the same effect as update command. It works both in tui and command line mode.

Upvotes: 3

greatwolf
greatwolf

Reputation: 20838

You can use

list *$eip

or the shorter form

l *$eip

This will instruct gdb to print the source lines near the current program counter.

Upvotes: 2

mkcs
mkcs

Reputation: 83

You can say l +0; the current line will be the first one listed.

The command l +offset lists the code starting from offset lines from the current line.

Note that, if you have already used the list command, the current line will have changed, i.e., it will no longer be the next executing line. So this will only work on your first list command.

Upvotes: 1

Employed Russian
Employed Russian

Reputation: 213406

It sounds like you want to run GDB in Emacs (which will show you current file and mark the current line), in DDD, or in tui mode.

Upvotes: 0

Related Questions