Skip to content
Advertisement

gdb catch syscall condition and string comparisson

I would like to catch a system call (more specifically access) and set a condition on it based on string comparison (obviously for arguments that are strings).

Specific example: when debugging ls I would like to catch access syscalls for specific pathnames (the 1st argument)

int access(const char *pathname, int mode);

So far, I have succeeded in manually inspecting the pathname argument of access (see [1]).

I tried to use this blog post:

JavaScript

but failed (see [2]), as gdb informed me of a segfault and that Evaluation of the expression containing the function (strcmp@plt) will be abandoned.. However gdb suggested set unwindonsignal on.

Which I tried:

JavaScript

but failed again (see [3]) with a similar error and the suggestion set unwindonsignal off

I searched for the The program being debugged was signaled while in a function called from GDB. error message, but (I think) I didn’t find something relevant.

Any help or ideas?

[1]

JavaScript

[2]

JavaScript

[3]

JavaScript

Advertisement

Answer

You can use the gdb internal function $_streq like this:

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement