Part 6 - Debugging char

Today we debug the char program. Let's review the code.

#include <stdio.h>
#include "pico/stdlib.h"

int main() 
{
  stdio_init_all();

  while(1) 
  {
    char x = 'x';
        
    printf("%c\n", x);

    sleep_ms(1000);
  }
        
  return 0;
}

Let's fire up our debugger.

radare2 -w arm -b 16 0x03_char.elf

Let's auto analyze.

aaaa

Let's seek to main.

s main

Let's go into visual mode by typing V and then p twice to get to a good debugger view.

We start out by setting up our main return value.

push {r4, lr}

We call the standard I/O init.

bl sym.stdio_init_all

We then load our format modifier %c into r4.

ldr r4, [0x0000033c]

We can prove it.

:> psz @ [0x0000033c]
%c

We then load our char 'x' into r1.

movs r1, 0x78

https://www.asciitable.com

You can check with above site that 0x78 hex is 'x'.

We then move our format modifier into r0.

movs r0, r4 

We then branch long to the printf wrapper and call it.

bl sym.__wrap_printf

We then move 250 decimal or 0xfa hex into r0.

movs r0, 0xfa

We then move 250 decimal, which we know when logical shift left twice will be 1,000 decimal or 0xfa hex into r0.

lsls r0, r0, 2

We then call the sleep_ms function.

bl sym.sleep_ms

We then continue the while loop infinitely.

b 0x328

In our next lesson we will hack the char data type.

results matching ""

    No results matching ""