Thread with 30 posts
jump to expanded postthe next release of touchHLE will have a new feature that 99.9% of users will never have a use for, but which will hopefully save me a lot of time/effort/suffering/tears in future
I implemented the GDB Remote Serial Protocol :3
https://github.com/hikari-no-yume/touchHLE/commit/00aa841ec2c12c94c6194adf64432ec10a404f93
here’s my review of the GDB Remote Serial Protocol, having implemented a small subset of it:
it’s… fine. the docs lack a few details, but you can figure them out from reading the GDB source code and from seeing how GDB responds to your packets. I’m glad it’s all ASCII.
I’m also glad it gracefully degrades. it assumes only the absolute minimum feature set. every single modern fancy feature is optional, because it’ll query or probe for support before trying to use those.
well… GDB will, at least. LLDB is another story ^^;;;;
I really appreciate that GDB hasn’t removed support for the deprecated way of doing multi-threading, because I think the modern way would be a pain to implement for me.
and now I found a (very annoying) GDB bug lol https://sourceware.org/bugzilla/show_bug.cgi?id=30234
I wrote a debugging guide 😤 https://github.com/hikari-no-yume/touchHLE/blob/trunk/DEBUGGING.md
using a real debugger is amazing, I can effectively insert debug prints into a binary:
(gdb) b *0x29a88
Breakpoint 1 at 0x29a88
(gdb) commands
Type commands for breakpoint(s) 1, one per line.
End with a line saying just "end".
>p *(char**)$r0
>continue
>end
(gdb) c
oh there’s actually a command for this: dprintf
the return on investment from implementing a GDB server in your emulator is incredible. my implementation is like 300 lines and does the bare minimum (memory and register read/write, step and continue), and now I have breakpoints, arbitrary C expression prints, disassembly view…
god as i drill deeper and deeper into this call stack, reverse-engineering this c++ app with no symbols, i keep fucking doing this to myself:
haha joke’s on me, some of them are std::wstring!!
words cannot describe how much better, more efficient, more effective, more fun the debugging experience is once you have an actual debugger to work with
i completely lost track of how many levels deep in the stack i got in this app, it was at least a dozen…
and then i discover that it can’t possibly be a problem with that bit of the code. in fact, it’s probably something very simple:
a missing slash in an absolute path
😅😅😅
(gdb) p *(char**)$r1
$5 = 0x3000b3ec "User/Applications/00000000-0000-0000-0000-", '0' <repeats 12 times>, "/FooBar.app"
gdb casting shade on the length of that UUID lmao
sometimes an app breaks your resolve. this app has finally done this to me. i haven’t the faintest idea why it’s making such strange assumptions about paths. everything i can gather tells me it must be wrong.
i’ll just… add the app-specific hack. just this once. it’s okay.
WAIT THE DYNAMIC LINKING FOR POSITION-INDEPENDENT CODE HAS BEEN BROKEN THIS ENTIRE TIME
h
how did i get three apps working already. how did this app get anywhere when it would literally write the function pointer to the wrong place. hhhh
😭
@hikari made my day 🤣
@hikari 300 lines? :O tutorial plx? >_>
@eniko honestly I think my current source code should be better than any tutorial: https://github.com/hikari-no-yume/touchHLE/blob/trunk/src/gdb.rs
(at least, it’s complete, and it should be easy to understand? happy to answer questions!)
@eniko I think there’s only three things in here that are optional (the “attached” query and accessing registers by number rather than as a block)
@eniko ah, the “kill” command is also optional, I have that just for convenience
@hikari i never knew i needed this
@hikari really impressive that it took so little code
I guess it makes sense since people often want gdb to work on tiny microcontrollers and stuff where having anything work on the guest device at all is shockingly difficult, so the debugger is under great pressure to do as much as possible with as little as possible.
@hikari tldr someone just have worked very hard to make that possible ❤️
@0x2ba22e11 yup! I have the luxury of TCP streams and a full-fat standard library, but this protocol was clearly intended for like, a microcontroller connected over serial!
@hikari ah congrats on the TAS API
@SoniEx2 lmao
@hikari Huh, so this behavior is a bug after all...
@_C arguably it’s not a bug but a missing feature, but without printing out a warning message, it’s hard for the user to know the intent
@hikari Ah. Damn, that's even worse. I don't understand how whoever worked on the asm layout didn't realize looking at what came before the current instruction is actually useful to diagnose problems. I lost count of how many times I had to rerun things just so I could set a breakpoint a few instructions before a crash. At least it seems it'll get fixed, so yay :)