radareorg / radare2

UNIX-like reverse engineering framework and command-line toolset
https://www.radare.org/
GNU Lesser General Public License v3.0
20.36k stars 2.97k forks source link

Add the AVR architecture in the debugger #3039

Closed XVilka closed 6 years ago

XVilka commented 9 years ago
radare commented 9 years ago

You mean for Linux-AVR?

XVilka commented 9 years ago

@radare yes, but r2 agent is optional, gdb:// protocol is more important.

XVilka commented 8 years ago

@radare @rlaemmert yesterday tried to debug the gdb:// protocol support for AVR. Added those 3 commits:

Now it works better with simulavr, but there still a problem with reading registers - drp command dumps the right regprofile, but dr prints only pc = 0x0000000 and nothing else:

[0x00000000]> drp
=PC    pc
=SP    sp
gpr     r0      .8      0       0
gpr     r1      .8      1       0
gpr     r2      .8      2       0
gpr     r3      .8      3       0
gpr     r4      .8      4       0
gpr     r5      .8      5       0
gpr     r6      .8      6       0
gpr     r7      .8      7       0
gpr     r8      .8      8       0
gpr     r9      .8      9       0
gpr     r10     .8      10      0
gpr     r11     .8      11      0
gpr     r12     .8      12      0
gpr     r13     .8      13      0
gpr     r14     .8      14      0
gpr     r15     .8      15      0
gpr     r16     .8      16      0
gpr     r17     .8      17      0
gpr     r18     .8      18      0
gpr     r19     .8      19      0
gpr     r20     .8      20      0
gpr     r21     .8      21      0
gpr     r22     .8      22      0
gpr     r23     .8      23      0
gpr     r24     .8      24      0
gpr     r25     .8      25      0
gpr     r26     .8      26      0
gpr     r27     .8      27      0
gpr     r28     .8      28      0
gpr     r29     .8      29      0
gpr     r30     .8      30      0
gpr     r31     .8      31      0
gpr     sreg    .8      32      0
gpr     sp      .16     33      0
gpr     pc      .32     35      0
[0x00000000]> dr=
  pc 0x00000000
[0x00000000]> drb
0x00000000  0xaaaaaaaa 0xaaaaaaaa 0xaaaaaaaa 0xaaaaaaaa  ................
0x00000010  0xaaaaaaaa 0xaaaaaaaa 0xaaaaaaaa 0xaaaaaaaa  ................
0x00000020  0x00000000                                ....

Here is the dump of the sent and received packets from the both sides: http://xvilka.me/avr-log.log

Steps to reproduce:

cd ~/simulavr/examples/atmega128_timer
avr-objcopy -O binary timer.elf timer.bin
src/simulavr -g -G -d atmega128 -f ../avr_examples/timer.elf -W 0x20,- -R 0x22,-
r2 -a avr -b 16 -D gdb gdb://localhost:1212

Latest simulavr git is here https://savannah.nongnu.org/git/?group=simulavr

Do you have any ideas of the reasons to do that?

radare commented 8 years ago

Because asm.bits is 16 and gpr are 8

On 17 May 2016, at 07:51, Anton Kochkov notifications@github.com wrote:

@radare @rlaemmert yesterday tried to debug the gdb:// protocol support for AVR. Added those 3 commits:

XVilka@3d41df5 XVilka@1bd277a XVilka@76fc898 Now it works better with simulavr, but there still a problem with reading registers - drp command dumps the right regprofile, but dr prints only pc = 0x0000000 and nothing else:

[0x00000000]> drp =PC pc =SP sp gpr r0 .8 0 0 gpr r1 .8 1 0 gpr r2 .8 2 0 gpr r3 .8 3 0 gpr r4 .8 4 0 gpr r5 .8 5 0 gpr r6 .8 6 0 gpr r7 .8 7 0 gpr r8 .8 8 0 gpr r9 .8 9 0 gpr r10 .8 10 0 gpr r11 .8 11 0 gpr r12 .8 12 0 gpr r13 .8 13 0 gpr r14 .8 14 0 gpr r15 .8 15 0 gpr r16 .8 16 0 gpr r17 .8 17 0 gpr r18 .8 18 0 gpr r19 .8 19 0 gpr r20 .8 20 0 gpr r21 .8 21 0 gpr r22 .8 22 0 gpr r23 .8 23 0 gpr r24 .8 24 0 gpr r25 .8 25 0 gpr r26 .8 26 0 gpr r27 .8 27 0 gpr r28 .8 28 0 gpr r29 .8 29 0 gpr r30 .8 30 0 gpr r31 .8 31 0 gpr sreg .8 32 0 gpr sp .16 33 0 gpr pc .32 35 0 [0x00000000]> dr= pc 0x00000000 [0x00000000]> drb 0x00000000 0xaaaaaaaa 0xaaaaaaaa 0xaaaaaaaa 0xaaaaaaaa ................ 0x00000010 0xaaaaaaaa 0xaaaaaaaa 0xaaaaaaaa 0xaaaaaaaa ................ 0x00000020 0x00000000 .... Here is the dump of the sent and received packets from the both sides: http://xvilka.me/avr-log.log

Steps to reproduce:

cd ~/simulavr/examples/atmega128_timer avr-objcopy -O binary timer.elf timer.bin src/simulavr -g -G -d atmega128 -f ../avr_examples/timer.elf -W 0x20,- -R 0x22,- r2 -a avr -b 16 -D gdb gdb://localhost:1212 Latest simulavr git is here https://savannah.nongnu.org/git/?group=simulavr

Do you have any ideas of the reasons to do that?

— You are receiving this because you were mentioned. Reply to this email directly or view it on GitHub

Maijin commented 8 years ago

image

radare commented 8 years ago

i didnt said to change bits at all. i just said that the current code only list 32 bit registers, and 8bit ones will fail because it deosnt matches with asm.bits, so its wrong. the only solution to this is to add another workaround like its done for other archs like arm or 8051

radare commented 8 years ago

also, the reg profiles must be changed to add another column with type information. otherwise we will be keep doing hacks and workarounds around this

XVilka commented 7 years ago

@SrimantaBarua seems this became even worse than it was...

XVilka commented 7 years ago

@SrimantaBarua: see:

simulavr -g -G -d atmega32 -f example.elf

then

r2 -a avr -b 16 -D gdb gdb://localhost:1212
= attach 6 6
debug_gdb_read_at: Error reading gdbserver memory (256 bytes at 0x0)
debug_gdb_read_at: Error reading gdbserver memory (256 bytes at 0x0)
 -- Press 'c' in visual mode to toggle the cursor mode
[0x00000000]> 

Seems that https://github.com/radare/radare2/pull/7703 and https://github.com/radare/radare2/pull/7692 didn't help much.

radare commented 7 years ago

From my tests, this servwr is not able to read more than 64 bytes in a row. And before it was segfaulting the server. So its not worst. Try switching to a smaller blocksize or use my branch

On 17 Jun 2017, at 11:14, Anton Kochkov notifications@github.com wrote:

@SrimantaBarua: see:

simulavr -g -G -d atmega32 -f example.elf then

r2 -a avr -b 16 -D gdb gdb://localhost:1212 = attach 6 6 debug_gdb_read_at: Error reading gdbserver memory (256 bytes at 0x0) debug_gdb_read_at: Error reading gdbserver memory (256 bytes at 0x0) -- Press 'c' in visual mode to toggle the cursor mode [0x00000000]> Seems that #7703 and #7692 didn't help much.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

SrimantaBarua commented 7 years ago

I think gdb protocol is working for simavr. dr will not work because as said reg sizes are different from pc size. But something like drt all works.

radare commented 7 years ago

I will try with the hw debugger when i have some spare time. Thanks!

On 17 Jun 2017, at 12:24, Pancake Nopcode pancake@nopcode.org wrote:

see:

XVilka commented 6 years ago

This is done. Sometimes not working - but then it's just implementation bug.