Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 661 Vote(s) - 3.49 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How do I set a conditional breakpoint in gdb, when char* x points to a string whose value equals "hello"?

#1
Can I specify that I want gdb to break at line x when `char* x` points to a string whose value equals `"hello"`? If yes, how?

Reply

#2
You can use `strcmp`:

break x:20 if strcmp(y, "hello") == 0

`20` is line number, `x` can be any filename and `y` can be any variable.
Reply

#3
break x if ((int)strcmp(y, "hello")) == 0

On some implementations gdb might not know the return type of strcmp. That means you would have to cast, otherwise it would always evaluate to true!
Reply

#4
Use a [break condition](

[To see links please register here]

) with `$_streq` (one of GDB's own [convenience functions](

[To see links please register here]

"current convenience functions online documentation")):
```gdb
break [where] if $_streq(x, "hello")
```
or, if your breakpoint already exists, add the condition to it:
```gdb
condition <breakpoint number> $_streq(x, "hello")
```

[Since GDB 7.5 (long ago)](

[To see links please register here]

"git commit, released 2012-08-17") you can use that and a handful of other native [convenience functions](

[To see links please register here]

"current online documentation") for various string matching, including `$_regex` which supports the [Python regex syntax](

[To see links please register here]

):
```gdb
$_memeq(buf1, buf2, length)
$_regex(str, regex)
$_streq(str1, str2)
$_strlen(str)
```

These are quite less problematic than having to execute the usual `strcmp()` injected to the process' stack, because that can have undesired side effects.

Alas, using the native functions is not always possible, because they rely on GDB being compiled with Python support. This is usually the default, but some constrained environments might not have it. To be sure, you can check it by running `show configuration` inside GDB and searching for `--with-python`. This shell oneliner does the trick, too:
```sh
gdb -n -quiet -batch -ex 'show configuration' | grep 'with-python'
```
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through