These are chat archives for o0rebelious0o/PolarProfile

12th
Feb 2015
Rich Evans
@o0rebelious0o
Feb 12 2015 14:15
PChien
can thou see?
Pierre
@planglois
Feb 12 2015 14:16
indeed
Rich Evans
@o0rebelious0o
Feb 12 2015 14:16
so
main file
#include <MK64F12.h>
#include <string.h>
#include "tfp_printf.h"

#define CHANNEL_DEBUG 0

#define NULL_PTR (void*)0

/* declared in minimal.ld */
extern const uint32_t StackTop;
extern int main( int, char *[] );

extern uint32_t __bss_start__, __bss_end__, __data_start__, __data_end__;
extern const uint32_t __data_start_src__;

#define VMPU_REGION_SIZE(p1,p2) ((p1>=p2)?0:(((uint32_t)p2)-((uint32_t)p1)))

/* print single character over SWO debug interface */
void PrintChar(char data)
{
    /* wait for TX */
    while (ITM->PORT[CHANNEL_DEBUG].u32 == 0);
    /* TX debug character */
    ITM->PORT[CHANNEL_DEBUG].u8 = (uint8_t)data;
}

/* reset function */
void OnReset(void)
{
    /* reset previous channel settings */
    ITM->LAR  = 0xC5ACCE55;
    ITM->TCR  = ITM->TER = 0x0;

    /* wait for debugger to connect */
    while (!((ITM->TCR & ITM_TCR_ITMENA_Msk) && (ITM->TER & (1 << CHANNEL_DEBUG))));

    CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk;
    DWT->CTRL |= DWT_CTRL_CYCCNTENA_Msk;

    /* reset uvisor BSS */
    memset(
        &__bss_start__,
        0,
        VMPU_REGION_SIZE(&__bss_start__, &__bss_end__)
    );
    /* initialize data if needed */
    memcpy(
        &__data_start__,
        &__data_start_src__,
        VMPU_REGION_SIZE(&__data_start__, &__data_end__)
    );

    platform_set_printf(tfp_printf);
    platform_set_fprintf(tfp_fprintf);

    tfp_printf("Starting main\r\n");
    uint32_t startCycnt = DWT->CYCCNT;
    main(0, NULL_PTR);
    uint32_t endCycnt = DWT->CYCCNT;
    tfp_printf("Finished main\r\n");
    tfp_printf("Main took %d cycles\r\n", endCycnt - startCycnt);

    while (1) {};
}


/* declare vector table */
__attribute__ ((section(".vtor")))
const void *VectorTable[] =
{
    &StackTop,
    OnReset
};
main bit is OnReset
void OnReset(void)
{
    /* reset previous channel settings */
    ITM->LAR  = 0xC5ACCE55;
    ITM->TCR  = ITM->TER = 0x0;

    /* wait for debugger to connect */
    while (!((ITM->TCR & ITM_TCR_ITMENA_Msk) && (ITM->TER & (1 << CHANNEL_DEBUG))));

    CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk;
    DWT->CTRL |= DWT_CTRL_CYCCNTENA_Msk;

    /* reset uvisor BSS */
    memset(
        &__bss_start__,
        0,
        VMPU_REGION_SIZE(&__bss_start__, &__bss_end__)
    );
    /* initialize data if needed */
    memcpy(
        &__data_start__,
        &__data_start_src__,
        VMPU_REGION_SIZE(&__data_start__, &__data_end__)
    );

    platform_set_printf(tfp_printf);
    platform_set_fprintf(tfp_fprintf);

    tfp_printf("Starting main\r\n");
    uint32_t startCycnt = DWT->CYCCNT;
    main(0, NULL_PTR);
    uint32_t endCycnt = DWT->CYCCNT;
    tfp_printf("Finished main\r\n");
    tfp_printf("Main took %d cycles\r\n", endCycnt - startCycnt);

    while (1) {};
}
if I set an OnReset breakpoint
it just continually loops
arm-none-eabi-gdb -x gdb.script
GNU gdb (GNU Tools for ARM Embedded Processors) 7.6.0.20140731-cvs
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "--host=i686-linux-gnu --target=arm-none-eabi".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
0x00000000 in ?? ()
Target endianess set to "little endian"
Target interface speed set to 1000 kHz
SWO enabled succesfully.
Selecting device: MK64FN1M0XXX12
gdb.script:7: Error in sourced command file:
tests/test_suite_arc4.elf: No such file or directory.
(gdb) load programs/hash/hello.elf
Loading section .text, size 0x20a0 lma 0x0
Loading section .data, size 0x4f8 lma 0x20a0
Start address 0x438, load size 9624
Transfer rate: 3132 KB/sec, 4812 bytes/write.
(gdb) file programs/hash/hello.elf
A program is being debugged already.
Are you sure you want to change the file? (y or n) y
Reading symbols from /home/riceva01/Documents/IoT/PolarProfile/programs/hash/hello.elf...done.
(gdb) b OnReset 
Breakpoint 1 at 0x43e: file core/main.c, line 29.
(gdb) c
Continuing.

Breakpoint 1, OnReset () at core/main.c:29
29          ITM->LAR  = 0xC5ACCE55;
(gdb)
Pierre
@planglois
Feb 12 2015 14:18
have you tried disasembling the vector table before and after the breakpoint?
Rich Evans
@o0rebelious0o
Feb 12 2015 14:19
why?
Pierre
@planglois
Feb 12 2015 14:19
it's possible GDB would override it with an instruction throwing a SIGTRAP, and then miserably forget to remove it when you hit the breakpoint
Rich Evans
@o0rebelious0o
Feb 12 2015 14:19
__attribute__ ((section(".vtor")))
const void *VectorTable[] =
{
    &StackTop,
    OnReset
};
Pierre
@planglois
Feb 12 2015 14:19
that's how normal breakpoints are implemented, replace the target instruction with a break, and when you hit it GDB puts it back
Rich Evans
@o0rebelious0o
Feb 12 2015 14:20
how can I read memory?
Pierre
@planglois
Feb 12 2015 14:20
x
x addr
disas VectorTable
Rich Evans
@o0rebelious0o
Feb 12 2015 14:20
x *0x0
0x20030000: Cannot access memory at address 0x20030000
Pierre
@planglois
Feb 12 2015 14:20
yeah, that's what I thought, it's in flash right?
Rich Evans
@o0rebelious0o
Feb 12 2015 14:21
Dump of assembler code for function VectorTable:
   0x00000000 <+0>:     movs    r0, r0
   0x00000002 <+2>:     movs    r0, #3
   0x00000004 <+4>:     lsls    r1, r7, #16
   0x00000006 <+6>:     movs    r0, r0
End of assembler dump.
doesn't look right
(gdb) b main
Breakpoint 2 at 0x71c: file polarssl/programs/hash/hello.c, line 50.
(gdb) c
Continuing.

Program received signal SIGTRAP, Trace/breakpoint trap.
0x00000000 in VectorTable ()
(gdb) disassemble VectorTable 
Dump of assembler code for function VectorTable:
=> 0x00000000 <+0>:     movs    r0, r0
   0x00000002 <+2>:     movs    r0, #3
   0x00000004 <+4>:     lsls    r1, r7, #16
   0x00000006 <+6>:     movs    r0, r0
End of assembler dump.
Pierre
@planglois
Feb 12 2015 14:25
so, it hits a break point (or an invalid instruction) at address 0x0?
Rich Evans
@o0rebelious0o
Feb 12 2015 14:26
I don't know
I don't know why it's even hitting that
Pierre
@planglois
Feb 12 2015 14:26
where are you when you get the SIGTRAP?
p/x $pc
p/i $pc
Rich Evans
@o0rebelious0o
Feb 12 2015 14:27
(gdb) p/x $pc
$1 = 0x0
Pierre
@planglois
Feb 12 2015 14:27
x/i $pc?
Rich Evans
@o0rebelious0o
Feb 12 2015 14:28
(gdb) x/i $pc
=> 0x0 <VectorTable>:   movs    r0, r0
it shouldn't be trying to execute that
I don't understand
Pierre
@planglois
Feb 12 2015 14:28
yeah
Rich Evans
@o0rebelious0o
Feb 12 2015 14:28
the code with main it should be calling
/*
 *  Classic "Hello, world" demonstration program
 *
 *  Copyright (C) 2006-2011, ARM Limited, All Rights Reserved
 *
 *  This file is part of mbed TLS (https://polarssl.org)
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License along
 *  with this program; if not, write to the Free Software Foundation, Inc.,
 *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

#if !defined(POLARSSL_CONFIG_FILE)
#include "polarssl/config.h"
#else
#include POLARSSL_CONFIG_FILE
#endif

#if defined(POLARSSL_PLATFORM_C)
#include "polarssl/platform.h"
#else
#define polarssl_printf     printf
#endif

#include <stdio.h>

#include "polarssl/md5.h"

#if !defined(POLARSSL_MD5_C)
int main( int argc, char *argv[] )
{
    ((void) argc);
    ((void) argv);

    polarssl_printf("POLARSSL_MD5_C not defined.\n");
    return( 0 );
}
#else
int main( int argc, char *argv[] )
{
    int i;
    unsigned char digest[16];
    char str[] = "Hello, world!";

    ((void) argc);
    ((void) argv);

    polarssl_printf( "\n  MD5('%s') = ", str );

    md5( (unsigned char *) str, 13, digest );

    for( i = 0; i < 16; i++ )
        polarssl_printf( "%02x", digest[i] );

    polarssl_printf( "\n\n" );

#if defined(_WIN32)
    polarssl_printf( "  Press Enter to exit this program.\n" );
    fflush( stdout ); getchar();
#endif

    return( 0 );
}
#endif /* POLARSSL_MD5_C */
int main( int argc, char *argv[] )
{
    int i;
    unsigned char digest[16];
    char str[] = "Hello, world!";

    ((void) argc);
    ((void) argv);

    polarssl_printf( "\n  MD5('%s') = ", str );

    md5( (unsigned char *) str, 13, digest );

    for( i = 0; i < 16; i++ )
        polarssl_printf( "%02x", digest[i] );

    polarssl_printf( "\n\n");

    return( 0 );
}
Pierre
@planglois
Feb 12 2015 14:29
like, can you backtrace?
and where do you come from when you hit this?
Rich Evans
@o0rebelious0o
Feb 12 2015 14:31
when I run without debugging I get
Starting main

  MD5('Hello, w�^C
have to ctrl+C to quit
if I add a wait before the call to md5, the full line polarssl_printf( "\n MD5('%s') = ", str ); prints
Pierre
@planglois
Feb 12 2015 14:32
oh, I don't know if it'll help but you can tell GDB to dump the RSP communication. So you'll see exactly what GDB tells your program to do
Rich Evans
@o0rebelious0o
Feb 12 2015 14:32
so it's crashing in there somewhere
how do I get a backtrace
or do you mean just step?
Pierre
@planglois
Feb 12 2015 14:32
set debug remote 1
Rich Evans
@o0rebelious0o
Feb 12 2015 14:32
(gdb) backtrace 
#0  0x00000000 in VectorTable ()
#1  0x00000000 in ?? ()
...helpful
Pierre
@planglois
Feb 12 2015 14:33
lol
it breaks before the stack is set up properly i guess
Rich Evans
@o0rebelious0o
Feb 12 2015 14:34
(gdb) set debug remote 1
(gdb) break OnReset
Sending packet: $m438,4#6c...Packet received: 80b582b0
Sending packet: $m43e,2#97...Packet received: 4ff0
Sending packet: $m43e,2#97...Packet received: 4ff0
Sending packet: $m43e,2#97...Packet received: 4ff0
Breakpoint 1 at 0x43e: file core/main.c, line 29.
Sending packet: $qTStatus#49...Packet received: 
(gdb) break main
Sending packet: $m71e,2#98...Packet received: 144b
Sending packet: $m720,2#64...Packet received: 88b0
Sending packet: $m71e,2#98...Packet received: 144b
Sending packet: $m720,2#64...Packet received: 88b0
Sending packet: $m71c,2#96...Packet received: 70b5
Breakpoint 2 at 0x71c: file polarssl/programs/hash/hello.c, line 50.
Sending packet: $qTStatus#49...Packet received: 
(gdb) break md5
Sending packet: $m1600,2#92...Packet received: 7040
Sending packet: $m1602,2#94...Packet received: 2de9
Sending packet: $m1604,2#96...Packet received: 0060
Sending packet: $m1606,2#98...Packet received: a0e1
Sending packet: $m1600,2#92...Packet received: 7040
Breakpoint 3 at 0x1600
Sending packet: $qTStatus#49...Packet received: 
(gdb) c
Continuing.
Sending packet: $qTStatus#49...Packet received: 
Sending packet: $Z0,43e,2#e0...Packet received: OK
Packet Z0 (software-breakpoint) is supported
Sending packet: $Z0,71c,2#df...Packet received: OK
Sending packet: $Z0,1600,2#db...Packet received: OK
Sending packet: $vCont?#49...Packet received: 
Packet vCont (verbose-resume) is NOT supported
Sending packet: $Hc0#db...Packet received: OK
Sending packet: $c#63...Packet received: T05
Sending packet: $g#67...Packet received: 00000000000000000000000000000000000000000000000000000000f0ff02200000000000000000000000000000000000000000f0ff0220ffffffff3e04000000000001f0ff02200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
Sending packet: $z0,43e,2#00...Packet received: OK
Sending packet: $z0,71c,2#ff...Packet received: OK
Sending packet: $z0,1600,2#fb...Packet received: OK

Sending packet: $m43e,4#99...Packet received: 4ff06043
Sending packet: $m2002ffc0,40#20...Packet received: 48656c6c6f2c20776f726c6421000000841e0000e4ff022000000000b1040000000000000000000000000000f0ff0220000000007708000000000000ffffffff
Breakpoint 1, OnReset () at core/main.c:29
29          ITM->LAR  = 0xC5ACCE55;
(gdb) c
Continuing.
Sending packet: $Hc0#db...Packet received: OK
Sending packet: $s#73...Packet received: T05
Sending packet: $g#67...Packet received: 000000000000000000000000000000e0000000000000000000000000f0ff02200000000000000000000000000000000000000000f0ff0220ffffffff4204000000000001f0ff02200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
Sending packet: $qTStatus#49...Packet received: 
Sending packet: $Z0,43e,2#e0...Packet received: OK
Sending packet: $Z0,71c,2#df...Packet received: OK
Sending packet: $Z0,1600,2#db...Packet received: OK
Sending packet: $Hc0#db...Packet received: OK
Sending packet: $c#63...Packet received: T05
Sending packet: $g#67...Packet received: 00000000000000000000000000000000000000000000000000000000f0ff02200000000000000000000000000000000000000000f0ff0220ffffffff3e04000000000001f0ff02200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
Sending packet: $z0,43e,2#00...Packet received: OK
Sending packet: $z0,71c,2#ff...Packet received: OK
Sending packet: $z0,1600,2#fb...Packet received: OK

Sending packet: $m43e,4#99...Packet received: 4ff06043
Sending packet: $m2002ffc0,40#20...Packet received: 48656c6c6f2c20776f726c6421000000841e0000e4ff022000000000b1040000000000000000000000000000f0ff0220000000007708000000000000ffffffff
Breakpoint 1, OnReset () at core/main.c:29
29          ITM->LAR  = 0xC5ACCE55;
it just loops there
then I remove it
(gdb) d 1
(gdb) info b
Num     Type           Disp Enb Address    What
2       breakpoint     keep y   0x0000071c in main at polarssl/programs/hash/hello.c:50
3       breakpoint     keep y   0x00001600 <md5>
(gdb) c
Continuing.
Sending packet: $qTStatus#49...Packet received: 
Sending packet: $Z0,71c,2#df...Packet received: OK
Sending packet: $Z0,1600,2#db...Packet received: OK
Sending packet: $c#63...Packet received: T05
Sending packet: $g#67...Packet received: 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000

Program received signal SIGTRAP, Trace/breakpoint trap.
Sending packet: $z0,71c,2#ff...Packet received: OK
Sending packet: $z0,1600,2#fb...Packet received: OK
Sending packet: $m0,4#fd...Packet received: 00000320
0x00000000 in VectorTable ()
interesting
2       breakpoint     keep y   0x0000071c in main at polarssl/programs/hash/hello.c:50
hello.c:50 is right
000006ec <main>:
     6ec:    b570          push    {r4, r5, r6, lr}
     6ee:    4b1b          ldr    r3, [pc, #108]    ; (75c <main+0x70>)
     6f0:    b08a          sub    sp, #40    ; 0x28
     6f2:    aa02          add    r2, sp, #8
     6f4:    f103 0608     add.w    r6, r3, #8
     6f8:    4615          mov    r5, r2
     6fa:    6818          ldr    r0, [r3, #0]
     6fc:    6859          ldr    r1, [r3, #4]
     6fe:    4614          mov    r4, r2
     700:    c403          stmia    r4!, {r0, r1}
     702:    3308          adds    r3, #8
     704:    42b3          cmp    r3, r6
     706:    4622          mov    r2, r4
     708:    d1f7          bne.n    6fa <main+0xe>
     70a:    6818          ldr    r0, [r3, #0]
     70c:    889b          ldrh    r3, [r3, #4]
     70e:    6020          str    r0, [r4, #0]
     710:    80a3          strh    r3, [r4, #4]
     712:    4813          ldr    r0, [pc, #76]    ; (760 <main+0x74>)
     714:    4629          mov    r1, r5
     716:    f7ff ffd7     bl    6c8 <tfp_printf>
     71a:    2300          movs    r3, #0
     71c:    9301          str    r3, [sp, #4]
     71e:    9a01          ldr    r2, [sp, #4]
     720:    4b10          ldr    r3, [pc, #64]    ; (764 <main+0x78>)
     722:    429a          cmp    r2, r3
     724:    dc02          bgt.n    72c <main+0x40>
     726:    9b01          ldr    r3, [sp, #4]
     728:    3301          adds    r3, #1
     72a:    e7f7          b.n    71c <main+0x30>
     72c:    480c          ldr    r0, [pc, #48]    ; (760 <main+0x74>)
but main isn't at 0x71c
wtf is going on
this is bullcrap
Pierre
@planglois
Feb 12 2015 14:39
that's just weird
Rich Evans
@o0rebelious0o
Feb 12 2015 14:40
(gdb) b *0x6ec
Breakpoint 1 at 0x6ec: file core/tfp_printf.c, line 216.
(gdb) info b
Num     Type           Disp Enb Address    What
1       breakpoint     keep y   0x000006ec in tfp_format at core/tfp_printf.c:216
(gdb) c
Continuing.

Program received signal SIGTRAP, Trace/breakpoint trap.
0x00000000 in VectorTable ()
that's all wrong
0x000006ec is the start of main
000006c8 <tfp_printf>:
     6c8:    b40f          push    {r0, r1, r2, r3}
     6ca:    b507          push    {r0, r1, r2, lr}
     6cc:    ab04          add    r3, sp, #16
     6ce:    2000          movs    r0, #0
     6d0:    f853 2b04     ldr.w    r2, [r3], #4
     6d4:    4904          ldr    r1, [pc, #16]    ; (6e8 <tfp_printf+0x20>)
     6d6:    9301          str    r3, [sp, #4]
     6d8:    f7ff ff4e     bl    578 <tfp_format>
     6dc:    b003          add    sp, #12
     6de:    f85d eb04     ldr.w    lr, [sp], #4
     6e2:    b004          add    sp, #16
     6e4:    4770          bx    lr
     6e6:    bf00          nop
     6e8:    00000573     .word    0x00000573
Pierre
@planglois
Feb 12 2015 14:45
yeah, I really don't know why it gets the wrong addresses, that looks like a bug. Although you get the same error when you put the right address in
but, disas main is right?
Rich Evans
@o0rebelious0o
Feb 12 2015 15:01
umm
looks like it's failing here
444: f8c3 2fb0 str.w r2, [r3, #4016] ; 0xfb0
i think the asm was wrong that I put
it was missing the printchar function for some reason
now the assembly numbers seem to match up
Pierre
@planglois
Feb 12 2015 15:03
hehe, gool old embedded debugging, the problem you see always look completely unrelated to what the actual problem is
Rich Evans
@o0rebelious0o
Feb 12 2015 15:03
yeah
either way
still happening
ok
dis is fucked up
changed the script to auto load the binary
Rich Evans
@o0rebelious0o
Feb 12 2015 15:08
as typing in load blah, file blah was annoying me
it now works
wtaf
(gdb) b main
Breakpoint 1 at 0x90a: file polarssl/programs/hash/hello.c, line 53.
(gdb) c
Continuing.

Breakpoint 1, main (argc=0, argv=0x0 <VectorTable>) at polarssl/programs/hash/hello.c:53
(gdb) b md5
Breakpoint 2 at 0x17f8
(gdb) c
Continuing.

Breakpoint 2, 0x000017f8 in md5 ()
fuck computers man
I'm gonna be a hermit
Pierre
@planglois
Feb 12 2015 15:09
so, GDB messes up the program by presumably adding breakpoints. So you need to load it again each time?
Rich Evans
@o0rebelious0o
Feb 12 2015 15:09
go live in a fucking cave
no
so before I was running make gdb
which generates its startup script
    target remote localhost:2331
    monitor endian little
    monitor halt
    monitor speed 1000
    monitor SWO EnableTarget 0 0 0x7 0
    monitor flash device = MK64FN1M0XXX12
    load programs/hash/hello.elf
    file programs/hash/hello.elf
    monitor reset
but before it was
    target remote localhost:2331
    monitor endian little
    monitor halt
    monitor speed 1000
    monitor SWO EnableTarget 0 0 0x7 0
    monitor flash device = MK64FN1M0XXX12
    load tests/arc4test.elf
    file tests/arc4test.elf
    monitor reset
so when it loaded, it could load those files as they didn't exist, I'm not debugging that
so I was manually loading the file myself
arm-none-eabi-gdb -x gdb.script
GNU gdb (GNU Tools for ARM Embedded Processors) 7.6.0.20140731-cvs
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "--host=i686-linux-gnu --target=arm-none-eabi".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
0x00000000 in ?? ()
Target endianess set to "little endian"
Target interface speed set to 1000 kHz
SWO enabled succesfully.
Selecting device: MK64FN1M0XXX12
gdb.script:7: Error in sourced command file:
tests/test_suite_arc4.elf: No such file or directory.
(gdb) load programs/hash/hello.elf
Loading section .text, size 0x20a0 lma 0x0
Loading section .data, size 0x4f8 lma 0x20a0
Start address 0x438, load size 9624
Transfer rate: 3132 KB/sec, 4812 bytes/write.
(gdb) file programs/hash/hello.elf
A program is being debugged already.
Are you sure you want to change the file? (y or n) y
Reading symbols from /home/riceva01/Documents/IoT/PolarProfile/programs/hash/hello.elf...done.
so you can see it said: gdb.script:7: Error in sourced command file: tests/test_suite_arc4.elf: No such file or directory.
which is fair enough
and immediately after I did
(gdb) load programs/hash/hello.elf
Loading section .text, size 0x20a0 lma 0x0
Loading section .data, size 0x4f8 lma 0x20a0
Start address 0x438, load size 9624
Transfer rate: 3132 KB/sec, 4812 bytes/write.
but changing the script generator so it loads it itself
...it works
fuck knows why
fml
wasted so many hours on this
Pierre
@planglois
Feb 12 2015 15:13
so, the only difference between the script and what you did manually is "monitor reset"
Rich Evans
@o0rebelious0o
Feb 12 2015 15:13
ummm
well
it was running the script
so unless
it stopped as soon as it had an error
in which case yes, I wasn't manually doing monitor reset
found where the crash happens
0x00000a18 in md5_process ()
0x00000000 in VectorTable ()
0x00000002 in VectorTable ()
0x00000004 in VectorTable ()
Pierre
@planglois
Feb 12 2015 15:14
the monitor commands are specific to the gdb server, GDB does not know what they do
Rich Evans
@o0rebelious0o
Feb 12 2015 15:15
i don't know what that means
0x00001394 in md5_process ()
0x00001396 in md5_process ()
0x00000ed8 in md5_process ()
0x00000eda in md5_process ()
0x00000a18 in md5_process ()
0x00000000 in VectorTable ()
0x00000002 in VectorTable ()
0x00000004 in VectorTable ()
0x00000006 in VectorTable ()
00000a00 <md5_process>:
     a00:    e92d0ff0     push    {r4, r5, r6, r7, r8, r9, sl, fp}
     a04:    e5d15002     ldrb    r5, [r1, #2]
     a08:    e5d1c001     ldrb    ip, [r1, #1]
     a0c:    e2802010     add    r2, r0, #16
     a10:    e5d14000     ldrb    r4, [r1]
     a14:    e8920044     ldm    r2, {r2, r6}
     a18:    e1a05805     lsl    r5, r5, #16
     a1c:    e590700c     ldr    r7, [r0, #12]
     a20:    e185540c     orr    r5, r5, ip, lsl #8
     a24:    e5d1c006     ldrb    ip, [r1, #6]
     a28:    e5908014     ldr    r8, [r0, #20]
     a2c:    e5909008     ldr    r9, [r0, #8]
     a30:    e0223006     eor    r3, r2, r6
     a34:    e1855004     orr    r5, r5, r4
     a38:    e59f2aa8     ldr    r2, [pc, #2728]    ; 14e8 <md5_process+0xae8>
     a3c:    e5d14005     ldrb    r4, [r1, #5]
...
     ed0:    e08cc001     add    ip, ip, r1
     ed4:    e084c96c     add    ip, r4, ip, ror #18
     ed8:    e59d1004     ldr    r1, [sp, #4]
     edc:    e59f264c     ldr    r2, [pc, #1612]    ; 1530 <md5_process+0xb30>
     ee0:    e02c6004     eor    r6, ip, r4
     ee4:    e0812002     add    r2, r1, r2
     ee8:    e0066003     and    r6, r6, r3
wtf. eda: isn't a valid address...
so for some reason the PC is incrementing by 2
Pierre
@planglois
Feb 12 2015 15:20
wait, you're not running thumb2?
Rich Evans
@o0rebelious0o
Feb 12 2015 15:22
are gcc and clang command line args the same?
Pierre
@planglois
Feb 12 2015 15:22
i think they try to be
but you'll always have different warning options
Rich Evans
@o0rebelious0o
Feb 12 2015 15:26
0xed8 <md5_process+1240>        asrs   r4, r0, #32                                                                                                                                                                                       │
  >│0xeda <md5_process+1242>        b.n    0xa18 <md5_process+24>                                                                                                                                                                            │
   │0xedc <md5_process+1244>        movs   r6, #76 ; 0x4c                                                                                                                                                                                    │
0x00001856 in md5 ()
0x00001394 in md5_process ()
0x00001396 in md5_process ()
0x00000ed8 in md5_process ()
0x00000eda in md5_process ()
0x00000a18 in md5_process ()
0x00000000 in VectorTable ()
interestingly, even though I can see it reaches md5_process
if I do
(gdb) b md5_process 
Breakpoint 1 at 0xa00
(gdb) c
Continuing.

Program received signal SIGTRAP, Trace/breakpoint trap.
0x00000000 in VectorTable ()
Rich Evans
@o0rebelious0o
Feb 12 2015 15:32
a18: isn't an instruction
0xa14 <md5_process+20>  lsls   r4, r0, #1                                                                                                                                                                                                │
   │0xa16 <md5_process+22>  ldmia.w        r2, {r0, r2, r11, r12, lr}                                                                                                                                                                        │
   │0xa1a <md5_process+26>  b.n    0xd5e <md5_process+862>                                                                                                                                                                                   │
   │0xa1c <md5_process+28>  strb   r4, [r1, #0]                                                                                                                                                                                              │
Rich Evans
@o0rebelious0o
Feb 12 2015 15:40
interesting
0xed0 <md5_process+1232>        stmia  r0!, {r0}                                                                                                                                                                                         │
   │0xed2 <md5_process+1234>        b.n    0xfee <md5_process+1518>                                                                                                                                                                          │
   │0xed4 <md5_process+1236>        ldmia  r1!, {r2, r3, r5, r6}                                                                                                                                                                             │
   │0xed6 <md5_process+1238>        b.n    0xfe2 <md5_process+1506>                                                                                                                                                                          │
   │0xed8 <md5_process+1240>        asrs   r4, r0, #32                                                                                                                                                                                       │
   │0xeda <md5_process+1242>        b.n    0xa18 <md5_process+24>                                                                                                                                                                            │
   │0xedc <md5_process+1244>        movs   r6, #76 ; 0x4c                                                                                                                                                                                    │0xede <md5_process+1246>        b.n    0xa20 <md5_process+32>                                                                                                                                                                            │
the code before the jump
that is completely different to what's in my asm file
from my asm file
     ed0:    e08cc001     add    ip, ip, r1
     ed4:    e084c96c     add    ip, r4, ip, ror #18
     ed8:    e59d1004     ldr    r1, [sp, #4]
how can that happen
ahh
unless when I objdump do I need to specify thumb2 or something?
Pierre
@planglois
Feb 12 2015 15:43
are you sure your asm file is correct?
yes
Rich Evans
@o0rebelious0o
Feb 12 2015 15:43
ah
Pierre
@planglois
Feb 12 2015 15:44
i was gonna say, it looks like arm code to me
Rich Evans
@o0rebelious0o
Feb 12 2015 15:44
that'll be it
Pierre
@planglois
Feb 12 2015 15:44
you don't have condition code in thumb2 assembly do you?
it's strange though, I though arm-none-elf-objdump would be thumb2 by default
wait no, of course not
Rich Evans
@o0rebelious0o
Feb 12 2015 15:45
it supports a7 too doesn't it
Pierre
@planglois
Feb 12 2015 15:45
yeah
Rich Evans
@o0rebelious0o
Feb 12 2015 15:45
so need to force v7m
Pierre
@planglois
Feb 12 2015 15:45
yeah, or just -mthumb2
or something
i don't know the option exactly
Rich Evans
@o0rebelious0o
Feb 12 2015 15:46
-b binary -marm -Mforce-thumb
this still seems wrong
changed my makefile to dump with those flags
Pierre
@planglois
Feb 12 2015 15:49
I though -marm was only for arm emcoding
Rich Evans
@o0rebelious0o
Feb 12 2015 15:49

but from GDB:

Dump of assembler code for function md5:
=> 0x000017f8 <+0>:     eors    r0, r6
   0x000017fa <+2>:     stmdb   sp!, {sp, lr}
   0x000017fe <+6>:     b.n     0x1b42 <md5_hmac_reset+2>
   0x00001800 <+8>:     beq.n   0x17c4 <md5_finish+244>
   0x00001802 <+10>:    b.n     0x1ca0 <md5_self_test+124>
   0x00001804 <+12>:    lsls    r4, r4, #4
   0x00001806 <+14>:    b.n     0x1348 <md5_process+2376>

in the asm:

000017f8 <md5>:
    17f8:    e92d4070     push    {r4, r5, r6, lr}
    17fc:    e1a06000     mov    r6, r0
    1800:    e24dd0e0     sub    sp, sp, #224    ; 0xe0
    1804:    e59f0124     ldr    r0, [pc, #292]    ; 1930 <md5+0x138>
    1808:    e1a05002     mov    r5, r2
    180c:    e1a04001     mov    r4, r1
I'm pretty sure gdb is right
but why would objdump be so fucked up
Pierre
@planglois
Feb 12 2015 15:50
yeah
Rich Evans
@o0rebelious0o
Feb 12 2015 16:35
fuck my life
FUCK
MY
LIFE
seriously
fuck it
hard
I've wasted nearly 5 hours on this shit
Starting main

  MD5('Hello, world!') = 6cd3556deb0da54bca060b4c39479839

Finished main
Main took 19716 cycles
Pierre
@planglois
Feb 12 2015 17:02
it works!