[lldb-dev] [Bug 47758] New: Stop with a watchpoint, only on register values
via lldb-dev
lldb-dev at lists.llvm.org
Wed Oct 7 23:14:03 PDT 2020
https://bugs.llvm.org/show_bug.cgi?id=47758
Bug ID: 47758
Summary: Stop with a watchpoint, only on register values
Product: lldb
Version: unspecified
Hardware: PC
OS: All
Status: NEW
Severity: enhancement
Priority: P
Component: All Bugs
Assignee: lldb-dev at lists.llvm.org
Reporter: rustymagnet3001 at gmail.com
CC: jdevlieghere at apple.com, llvm-bugs at lists.llvm.org
If a system call is written with inline ASM and C, how do you stop lldb when
you don't know which function calls the syscall and you (only) want rely on the
registers containing values that match the syscall you are expecting? Do I
want gdb's `catch syscall` in lldb ? Is a better way to solve the issue with
existing lldb capabilities?
/*************************/
(lldb) b syscall
Breakpoint 2: where = libsystem_kernel.dylib`__syscall, address =
0x00007fff522079f0
/** Breakpoint fires **/
(lldb) frame info
frame #0: 0x00007fff522079f0 libsystem_kernel.dylib`__syscall
(lldb) po (char *) $arg2
"/path/to/debugger_challenge.app/Info.plist"
/*************************/
I can extend this breakpoint with a condition. It almost achieves what I want.
The breakpoint stops in syscall when a substring is found in one register:
`br s -n syscall -c '(char *) strnstr((char *)$rsi, "Info.plist",
(int)strlen((char *) $rsi)) != NULL'`
I got this idea from Jim Ingham:
https://stackoverflow.com/questions/36679156/lldb-how-to-set-breakpoint-whch-stops-when-register-somevalue
/******* Challenge *******/
If the same syscall is written with inline ASM and C, a `syscall` breakpoint
won't fire, as expected. I can't place a breakpoint as I don't have a function
name to feed the breakpoint. I don't know where in the binary contains the
`svc` opcode.
I tried `watchpoints` but these never seemed to trigger correctly.
watchpoint set expression -w read_write -- $rsi
watchpoint set expression -w read -- $arg2
For completeness, please see an arm64 example of inline ASM that calls the C
API Access() to check if a file exists:
/******* code that calls ASM function *******/
NSString *filepath = [appbundle pathForResource:@"Info" ofType:@"plist"];
const char *fp = filepath.fileSystemRepresentation;
#if defined(__arm64__)
int64_t result = [self asmSyscallFunction:fp];
/******* Inline ASM function *******/
+(int64_t) asmSyscallFunction:(const char *) fp{
int64_t res = 99; // signed 64 bit wide int, as api can
return -1
#if defined(__arm64__)
__asm (
"mov x0, #33\n" // access syscall number on arm
"mov x1, %[input_path]\n" // copy char* to x1
"mov x2, #0\n" // File exist check == 0
"mov x16, #0\n"
"svc #33\n"
"mov %[result], x0 \n"
: [result] "=r" (res)
: [input_path] "r" (fp)
: "x0", "x1", "x2", "x16", "memory"
);
#endif
return res;
}
--
You are receiving this mail because:
You are the assignee for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/lldb-dev/attachments/20201008/93e38da2/attachment.html>
More information about the lldb-dev
mailing list