Читаем Linux программирование в примерах полностью

 l1 = 134828624}, r = {rptr = 0x0, pptr = 0, preg = 0x0,

 hd = 0x0, av = 0x0, r_ent =0}, x = {extra = 0x0, x1 = 0,

 param_list = 0x0},

 name = 0x0, number = 1, reflags = 0}, val = {

 fltnum = 6.6614191194446594e-316, sp = 0x0, slen = 0, sref = 1,

 idx = 0}, hash = {next = 0x8095250, name = 0x0, length = 0, value = 0x0,

 ref = 1}}, type = Node_expression_list, flags = 1}

В заключение, команда cont (continue — продолжить) дает возможность продолжить выполнение программы. Она будет выполняться до следующей контрольной точки или до нормального завершения, если других контрольных точек нет. Этот пример продолжается с того места, на котором остановился предыдущий:

1520 for (numnodes = 0; tree != NULL; tree = tree->rnode)

(gdb) cont /* Продолжить *!

Continuing.

hello, world


Program exited normally. /* Сообщение от GDB */

(gdb) quit /* Выйти из отладчика */

Отслеживаемая точка (watchpoint) подобна контрольной точке, но используется для данных, а не для кода. Отслеживаемые точки устанавливаются для переменной (или поля структуры или объединения или элемента массива), при их изменении GDB посылает уведомления. GDB проверяет значение отслеживаемой точки по мере пошагового исполнения программы и останавливается при изменении значения. Например, переменная do_lint_old в gawk равна true, когда была использована опция --lint_old. Эта переменная устанавливается в true функцией getopt_long(). (Мы рассмотрели getopt_long() в разделе 2.1.2 «Длинные опции GNU»). В файле main.c программы gawk:

int do_lint_old = FALSE;

 /* предупредить о материале, не имевшейся в V7 awk */

...

static const struct option optab[] = {

 ...

 { "lint-old", no_argument, &do_lint_old, 1 },

 ...

};

Вот пример сеанса, показывающего отслеживаемую точку в действии:

$ gdb gawk /* Запустить GDB с gawk */

GNU gdb 5.3

...

(gdb) watch do_lint_old

 /* Установить отслеживаемую точку для переменной */

Hardware watchpoint 1: do_lint_old

(gdb) run --lint-old 'BEGIN { print "hello, world" }'

 /* Запустить программу */

Starting program: /home/arnold/Gnu/gawk/gawk-3.1.4/gawk —lint-old

'BEGIN { print "hello, world" }'

Hardware watchpoint 1: do_lint_old

Hardware watchpoint 1: do_lint_old

Hardware watchpoint 1: do_lint_old

 /* Проверка отслеживаемой точки при работе программы */

Hardware watchpoint 1: do_lint_old

Hardware watchpoint 1: do_lint_old

Old value = 0 /* Отслеживаемая точка останавливает программу */

New value = 1

0x420c4219 in _getopt_internal() from /lib/i686/libc.so.6

(gdb) where /* Трассировка стека */

#0 0x420c4219 in _getopt_internal() from /lib/i686/libc.so.6

#1 0x420c4e83 in getopt_long() from /lib/i686/libc.so.6

#2 0x080683a1 in main (argc=3, argv=0xbffff8a4) at main.c:293

#3 0x420158d4 in __libc_start_main() from /lib/i686/libc.so.6

(gdb) quit /* На данный момент мы закончили */

The program is running. Exit anyway? (y or n) y /* Да */

GDB может делать гораздо больше, чем мы здесь показали. Хотя руководство GDB большое, его стоит прочесть целиком хотя бы один раз, чтобы ознакомиться с его командами и возможностями. После этого, возможно, будет достаточно просмотреть файл NEWS в каждом новом дистрибутиве GDB, чтобы узнать, что нового или что изменилось.

Перейти на страницу:

Похожие книги

C++ Primer Plus
C++ Primer Plus

C++ Primer Plus is a carefully crafted, complete tutorial on one of the most significant and widely used programming languages today. An accessible and easy-to-use self-study guide, this book is appropriate for both serious students of programming as well as developers already proficient in other languages.The sixth edition of C++ Primer Plus has been updated and expanded to cover the latest developments in C++, including a detailed look at the new C++11 standard.Author and educator Stephen Prata has created an introduction to C++ that is instructive, clear, and insightful. Fundamental programming concepts are explained along with details of the C++ language. Many short, practical examples illustrate just one or two concepts at a time, encouraging readers to master new topics by immediately putting them to use.Review questions and programming exercises at the end of each chapter help readers zero in on the most critical information and digest the most difficult concepts.In C++ Primer Plus, you'll find depth, breadth, and a variety of teaching techniques and tools to enhance your learning:• A new detailed chapter on the changes and additional capabilities introduced in the C++11 standard• Complete, integrated discussion of both basic C language and additional C++ features• Clear guidance about when and why to use a feature• Hands-on learning with concise and simple examples that develop your understanding a concept or two at a time• Hundreds of practical sample programs• Review questions and programming exercises at the end of each chapter to test your understanding• Coverage of generic C++ gives you the greatest possible flexibility• Teaches the ISO standard, including discussions of templates, the Standard Template Library, the string class, exceptions, RTTI, and namespaces

Стивен Прата

Программирование, программы, базы данных