Xroar trace filtering...

Hardware Hacking, Programming and Game Solutions/Cheats
Post Reply
jedie
Posts: 655
Joined: Wed Aug 14, 2013 12:23 pm
Location: germany
Contact:

Xroar trace filtering...

Post by jedie »

I started a simple python script to filter Xroar trace files...

The idea is simple: Skip lines with addresses that are calles very often, e.g.:
* The "how many RAM is installed" ROM routine
* The BASIC Interpreter idle loop

So you can see the really interesting parts of the trace...

I put the script to here: https://github.com/jedie/PyDragon32/blo ... r_trace.py

It's WIP and not really usable, yet. (Release early, release often :) )
I will create a CLI, today.
... too many ideas and too little time ... Related stuff written in Python:
Dragon 32 emulator / PyDC - Python Dragon 32 converter: https://github.com/jedie/DragonPy
DWLOAD server / Dragon-Lib and other stuff: https://github.com/6809
jedie
Posts: 655
Joined: Wed Aug 14, 2013 12:23 pm
Location: germany
Contact:

Re: Xroar trace filtering...

Post by jedie »

OK, it's now usable:

Code: Select all

$ python filter_xroar_trace.py --help
usage: filter_xroar_trace.py [-h] [--display [MAX]] [--filter [MAX]]
                             infile [outfile]

Filter Xroar traces

positional arguments:
  infile           Xroar trace file.
  outfile          If given: write output in a new file else: Display it.

optional arguments:
  -h, --help       show this help message and exit
  --display [MAX]  Display statistics how often a address is called.
  --filter [MAX]   Filter the trace: skip addresses that called more than
                   given count.
More Info and examples, see README here: https://github.com/jedie/PyDragon32/tree/master/misc
... too many ideas and too little time ... Related stuff written in Python:
Dragon 32 emulator / PyDC - Python Dragon 32 converter: https://github.com/jedie/DragonPy
DWLOAD server / Dragon-Lib and other stuff: https://github.com/6809
jedie
Posts: 655
Joined: Wed Aug 14, 2013 12:23 pm
Location: germany
Contact:

Re: Xroar trace filtering...

Post by jedie »

I commit a real nice feature: Live trace filtering ;) (see commit https://github.com/jedie/PyDragon32/com ... f80773b8aa )

How it works:

Create a startup trace:

Code: Select all

$ xroar -trace > startup_trace.txt 
Let xroar start the machine e.g.: until the prompt is blicking. Then quit xroar.

Start again with the created startup_trace.txt file:

Code: Select all

$ xroar -trace | python filter_xroar_trace.py --loop-filter startup_trace.txt
Now you will see only trace output for addresses that aren't in startup_trace.txt ;)


So you can see only the real parts of the trace ;)
... too many ideas and too little time ... Related stuff written in Python:
Dragon 32 emulator / PyDC - Python Dragon 32 converter: https://github.com/jedie/DragonPy
DWLOAD server / Dragon-Lib and other stuff: https://github.com/6809
jedie
Posts: 655
Joined: Wed Aug 14, 2013 12:23 pm
Location: germany
Contact:

Re: Xroar trace filtering...

Post by jedie »

e.g.:
I created a startup_trace.txt with only run PRINT "A", then i start filtering with PRINT 6 and this is the result: https://gist.github.com/jedie/ab730ed530c67c96218f

The startup trace is ~165MB big. The filtered file is only ~200KB small...
... too many ideas and too little time ... Related stuff written in Python:
Dragon 32 emulator / PyDC - Python Dragon 32 converter: https://github.com/jedie/DragonPy
DWLOAD server / Dragon-Lib and other stuff: https://github.com/6809
sixxie
Posts: 1346
Joined: Fri Jul 18, 2008 8:36 am
Location: Hertfordshire
Contact:

Re: Xroar trace filtering...

Post by sixxie »

Sounds interesting - must remember to try this next time I have needles to pick out of the haystack!
jedie
Posts: 655
Joined: Wed Aug 14, 2013 12:23 pm
Location: germany
Contact:

Re: Xroar trace filtering...

Post by jedie »

Add a second script that add address information into the trace.

Use the ROM Info file from: https://github.com/6809/rom-info

e.g.:

Code: Select all

xroar -trace | python add_info_in_trace.py --infofile Dragon32.txt
or better: Combine both scripts:

Code: Select all

$ xroar -trace | python filter_xroar_trace.py --loop-filter startup_trace.txt | python add_info_in_trace.py --infofile Dragon32.txt
Output looks like:

Code: Select all

... [Skip 14 lines] ...
897a| 9e64        LDX     <$64                cc=a1 a=ff b=fd dp=00 x=02e2 y=804b u=7fff s=7f2c | $897a: $8000-$9fff -  CoCo - Extended Color BASIC ROM
897c| 9fa6        STX     <$a6                cc=a1 a=ff b=fd dp=00 x=02e2 y=804b u=7fff s=7f2c | $897c: $8000-$9fff -  CoCo - Extended Color BASIC ROM
897e| 39          RTS                         cc=a1 a=ff b=fd dp=00 x=02e2 y=804b u=7fff s=7f2e | $897e: $8000-$9fff -  CoCo - Extended Color BASIC ROM
8897| 0f3f        CLR     <$3f                cc=a4 a=ff b=fd dp=00 x=02e2 y=804b u=7fff s=7f2e | $8897: $8000-$9fff -  CoCo - Extended Color BASIC ROM
8899| 9da5        JSR     <$a5                cc=a4 a=ff b=fd dp=00 x=02e2 y=804b u=7fff s=7f2c | $8899: $8000-$9fff -  CoCo - Extended Color BASIC ROM
00a5| b602e2      LDA     $02e2               cc=a4 a=00 b=fd dp=00 x=02e2 y=804b u=7fff s=7f2c | $a5: $a5-$a7 -  LDA >xxxx
00a8| 7ebb26      JMP     $bb26               cc=a4 a=00 b=fd dp=00 x=02e2 y=804b u=7fff s=7f2c | $a8: $a8-$aa -  JMP $BB26
bb26| 813a        CMPA    #$3a                cc=a9 a=00 b=fd dp=00 x=02e2 y=804b u=7fff s=7f2c | $bb26: $bb26-$bb34 -  Jumped to from selfmodifying CHRGET routine at $009f
bb28| 240a        BCC     $bb34               cc=a9 a=00 b=fd dp=00 x=02e2 y=804b u=7fff s=7f2c | $bb28: $bb26-$bb34 -  Jumped to from selfmodifying CHRGET routine at $009f
bb2a| 8120        CMPA    #$20                cc=a9 a=00 b=fd dp=00 x=02e2 y=804b u=7fff s=7f2c | $bb2a: $bb26-$bb34 -  Jumped to from selfmodifying CHRGET routine at $009f
bb2c| 2602        BNE     $bb30               cc=a9 a=00 b=fd dp=00 x=02e2 y=804b u=7fff s=7f2c | $bb2c: $bb26-$bb34 -  Jumped to from selfmodifying CHRGET routine at $009f
bb30| 8030        SUBA    #$30                cc=a9 a=d0 b=fd dp=00 x=02e2 y=804b u=7fff s=7f2c | $bb30: $bb26-$bb34 -  Jumped to from selfmodifying CHRGET routine at $009f
bb32| 80d0        SUBA    #$d0                cc=a4 a=00 b=fd dp=00 x=02e2 y=804b u=7fff s=7f2c | $bb32: $bb26-$bb34 -  Jumped to from selfmodifying CHRGET routine at $009f
bb34| 39          RTS                         cc=a4 a=00 b=fd dp=00 x=02e2 y=804b u=7fff s=7f2e | $bb34: $bb26-$bb34 -  Jumped to from selfmodifying CHRGET routine at $009f
889b| 80ca        SUBA    #$ca                cc=a1 a=36 b=fd dp=00 x=02e2 y=804b u=7fff s=7f2e | $889b: $8000-$9fff -  CoCo - Extended Color BASIC ROM
889d| 2513        BCS     $88b2               cc=a1 a=36 b=fd dp=00 x=02e2 y=804b u=7fff s=7f2e | $889d: $8000-$9fff -  CoCo - Extended Color BASIC ROM
EDIT: Maybe i will also made a HTML Output that can look like this:
https://www.jensdiemer.de/media/dragonp ... 51212.html (short file)
https://www.jensdiemer.de/media/dragonp ... 51708.html (WARNING: Big trace!)
... too many ideas and too little time ... Related stuff written in Python:
Dragon 32 emulator / PyDC - Python Dragon 32 converter: https://github.com/jedie/DragonPy
DWLOAD server / Dragon-Lib and other stuff: https://github.com/6809
jedie
Posts: 655
Joined: Wed Aug 14, 2013 12:23 pm
Location: germany
Contact:

Re: Xroar trace filtering...

Post by jedie »

Have done some updates:

--unique
To create a "small" startup trace, do this:

Code: Select all

$ xroar -trace  | python filter_xroar_trace.py --unique | tee startup_trace.txt 
"unique" will only collect a address one time. So "startup_trace.txt" is very small.
It skips all trace lines, if the addresses was called in the past.

--start-stop
You will see traces only if $1234 was called and until $5678 is called, then e.g.:

Code: Select all

$ xroar -trace | python filter_xroar_trace.py --start-stop=1234-5678 | tee routine_trace.txt
Note: You will not only see trace lines if address is between 1234 and 5678!
You can also do this: --start-stop=9876-1234 So, it starts if $9876 is called and stops if $1234 is called.


This is really helpfull, for my "Assembler Text BASIC scripts" like: testCC_SUBA.bas (see: https://github.com/jedie/PyDragon32/tre ... _Registers )

You know the entry point for the machine code e.g.: $4000 and you see the end code (in this case $4050).
If you will only see the machine test code, do this:

Code: Select all

$ xroar -trace | python filter_xroar_trace.py --start-stop=4000-4050 | tee suba_trace.txt
:D



filter_xroar_trace.py is here: https://github.com/jedie/PyDragon32/tree/master/misc
Quick Download: https://raw.githubusercontent.com/jedie ... r_trace.py
or:

Code: Select all

wget https://raw.githubusercontent.com/jedie/PyDragon32/master/misc/filter_xroar_trace.py
... too many ideas and too little time ... Related stuff written in Python:
Dragon 32 emulator / PyDC - Python Dragon 32 converter: https://github.com/jedie/DragonPy
DWLOAD server / Dragon-Lib and other stuff: https://github.com/6809
User avatar
tormod
Posts: 416
Joined: Sat Apr 27, 2013 12:06 pm
Location: Switzerland
Contact:

Re: Xroar trace filtering...

Post by tormod »

The --start-stop option seems really useful! I would like to have the ability of toggling the trace from gdb, so that I can for instance turn on the trace in one breakpoint and turn it off again in another. Maybe the gdb "signal" command can be used for this.
Post Reply