8

Is it possible to run code inside gdb? For example, if I were debugging a .c file, and I wanted to get the strlen() of a character array at a particular point in time, I can't just type in strlen(str) into the buffer - it is an invalid command. What can I do?

2
  • You could try using the print command, I am not sure if it allows you to call arbitrary functions though Commented Feb 16, 2014 at 18:38
  • Not only is it possible (in most cases), you can even set and hit breakpoints inside code you explicitly evaluate Commented Feb 16, 2014 at 20:06

1 Answer 1

10

From gdb prompt call strlen(the_char_array). Eg.,

(gdb) call strlen(the_char_array)
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.