Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I write a loop in a gdb script?

Tags:

gdb

fortran

After adapting this answer, I wrote the following loop to simply print an array in gdb in a script called "gdb_script.gs". What am I doing wrong?

set $end=64  
while ($i<$end)
   print $i
   print volfrac($i, :, 1)
   set $i=$i+1
end

where volfrac(:,:,:) is a fortran array. I am getting the error:

 gdb_script.gs:14: Error in sourced command file:
 A syntax error in expression, near `<$end)'.
like image 590
wander95 Avatar asked Sep 27 '17 18:09

wander95


People also ask

How do you write a loop in gdb?

(gdb) print /x volfrac[0][0][0] $5 = 0xdeadbeef (gdb) print /x volfrac[0][0] $6 = {0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0x0, 0x0, 0x0, 0x0} (gdb) print /x volfrac[0] $7 = {{0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, (gdb) print /x volfrac $8 = {{{ ...

What does print do in gdb?

The usual way to examine data in your program is with the print command (abbreviated p ), or its synonym inspect . It evaluates and prints the value of an expression of the language your program is written in (see section Using GDB with Different Languages). expr is an expression (in the source language).

How do you break out of gdb?

Quitting GDB To exit GDB, use the quit command (abbreviated q ), or type an end-of-file character (usually C-d ). If you do not supply expression , GDB will terminate normally; otherwise it will terminate using the result of expression as the error code.


1 Answers

set $i = 0
p $i++

keep pressing Enter this is one of the easiest logic I found

like image 162
Ravi Kumar Yadav Avatar answered Sep 28 '22 09:09

Ravi Kumar Yadav