--debug-vm-args affects --debug-vm-rr, fix #112

This commit is contained in:
Ciro Santilli 六四事件 法轮功
2020-01-07 00:00:01 +00:00
parent 2cfe56decf
commit d5876c9980
2 changed files with 20 additions and 4 deletions

View File

@@ -9969,7 +9969,7 @@ While step debugging any complex program, you always end up feeling the need to
While GDB "has" this feature, it is just too broken to be usable, and so we expose the amazing Mozilla RR tool conveniently in this repo: https://stackoverflow.com/questions/1470434/how-does-reverse-debugging-work/53063242#53063242
Before the first usage:
Before the first usage setup rr with:
....
echo 'kernel.perf_event_paranoid=1' | sudo tee -a /etc/sysctl.conf
@@ -9982,7 +9982,10 @@ Then use it with your content of interest, for example:
./run --debug-vm-rr --userland userland/c/hello.c
....
This will first run the program once until completion, and then restart the program at the very first instruction at `_start` and leave you in a GDB shell.
This will:
* first run the program once until completion or crash
* then restart the program at the very first instruction at `_start` and leave you in a GDB shell
From there, run the program until your point of interest, e.g.:
@@ -9999,6 +10002,12 @@ To restart debugging again after quitting `rr`, simply run on your host terminal
rr replay
....
The use case of `rr` is often to go to the final crash and then walk back from there, so you often want to automate running until the end after record with `--debug-vm-args` as in:
....
./run --debug-vm-args='-ex continue' --debug-vm-rr --userland userland/c/hello.c
....
Programs often tend to blow up in very low frames that use values passed in from higher frames. In those cases, remember that just like with forward debugging, you can't just go:
....

11
run
View File

@@ -2,6 +2,7 @@
import os
import re
import shlex
import shutil
import subprocess
import sys
@@ -44,7 +45,10 @@ See also: https://cirosantilli.com/linux-kernel-module-cheat#debug-the-emulator
self.add_argument(
'--debug-vm-args',
default='',
help='Like --debug-vm, but also pass arguments to GDB'
help='''\
Pass arguments to GDB. Implies --debug-vm. If --debug-vm-rr is used,
pass the given arguments to GDB on the replay.
'''
)
self.add_argument(
'--debug-vm-file',
@@ -841,8 +845,11 @@ Extra options to append at the end of the emulator command line.
stdin_path=self.env['stdin_file'],
)
if self.env['debug_vm_rr']:
rr_cmd = ['rr', 'replay', LF, '-o', '-q', LF]
for arg in shlex.split(self.env['debug_vm_args']):
rr_cmd.extend(['-o', arg, LF]);
exit_status = self.sh.run_cmd(
['rr', 'replay', '-o', '-q'],
rr_cmd,
raise_on_failure=False,
show_stdout=show_stdout,
)