From a53c22e31fc272d5cc0ef20ac8bc63ef0e9ac6d7 Mon Sep 17 00:00:00 2001 From: Lukas Date: Thu, 24 Oct 2024 10:48:06 +0200 Subject: [PATCH 1/6] traceDecoder_etm4 bug fixes --- Src/traceDecoder_etm4.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/Src/traceDecoder_etm4.c b/Src/traceDecoder_etm4.c index d90c7f8a..90caa9ac 100644 --- a/Src/traceDecoder_etm4.c +++ b/Src/traceDecoder_etm4.c @@ -185,6 +185,11 @@ static bool _pumpAction( struct TRACEDecoderEngine *e, struct TRACECPUState *cpu } else { + if( c == 0x05 && j->asyncCount == 1) + { + cpu->overflows++; + DEBUG( "Overflow Detected. ReSync Trace Stream:" EOL ); + } j->asyncCount = c ? 0 : j->asyncCount + 1; switch ( j->p ) @@ -336,7 +341,7 @@ static bool _pumpAction( struct TRACEDecoderEngine *e, struct TRACECPUState *cpu case 0b11000000 ... 0b11010100: case 0b11100000 ... 0b11110100: /* Atom format 6, Figure 6-44, Pg 6.307 */ - cpu->eatoms = ( c & 0x1f ) + 3; + cpu->eatoms = ( c & 0x1f ) + 4; cpu->instCount = cpu->eatoms; cpu->disposition = ( 1 << ( cpu->eatoms ) ) - 1; @@ -404,6 +409,8 @@ static bool _pumpAction( struct TRACEDecoderEngine *e, struct TRACECPUState *cpu cpu->addr = j->q[match].addr; retVal = TRACE_EV_MSG_RXED; _stateChange( cpu, EV_CH_ADDRESS ); + _stackQ( j ); + j->q[0].addr = cpu->addr; break; case 0b10010101: /* Short address, IS0 short, Figure 6-32, Pg 6-294 */ @@ -685,7 +692,7 @@ static bool _pumpAction( struct TRACEDecoderEngine *e, struct TRACECPUState *cpu } else { - if ( j->idx == 8 ) + if ( j->idx == 9 ) { /* Second byte of IS1 case - mask MSB */ j->q[0].addr = ( j->q[0].addr & ( ~( 0x7F << j->idx ) ) ) | ( ( c & 0x7f ) << ( j->idx ) ); From 3c326d2d3759fc20c9784493021f2fe2776bb6a9 Mon Sep 17 00:00:00 2001 From: Lukas Date: Thu, 24 Oct 2024 11:04:05 +0200 Subject: [PATCH 2/6] TraceDecoder add overflow debug parameter --- Inc/traceDecoder.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Inc/traceDecoder.h b/Inc/traceDecoder.h index a134f191..1940d945 100644 --- a/Inc/traceDecoder.h +++ b/Inc/traceDecoder.h @@ -143,6 +143,9 @@ struct TRACECPUState // Convinience, for debug reporting genericsReportCB report; + + // Debugging + uint64_t overflows; }; // ============================================================================ From 29c8a18e60c46cfc3be15c47a2579e86e82e0dff Mon Sep 17 00:00:00 2001 From: Lukas Date: Thu, 24 Oct 2024 11:12:19 +0200 Subject: [PATCH 3/6] loadelf fix could not find inline functions, LDR was missing --- Src/loadelf.c | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/Src/loadelf.c b/Src/loadelf.c index ea3295a1..511c14d0 100644 --- a/Src/loadelf.c +++ b/Src/loadelf.c @@ -369,15 +369,16 @@ static void _processFunctionDie( struct symbol *p, Dwarf_Debug dbg, Dwarf_Die di attr_tag = DW_AT_abstract_origin; dwarf_attr( die, attr_tag, &attr_data, 0 ); dwarf_global_formref( attr_data, &abstract_origin_offset, 0 ); - dwarf_offdie_b( dbg, abstract_origin_offset, IS_INFO, &abstract_origin_die, 0 ); - isinline = true; - } - else - { - dwarf_highpc_b ( die, &h, 0, &formclass, 0 ); - dwarf_lowpc ( die, &l, 0 ); + if (DW_DLV_OK == dwarf_offdie_b( dbg, abstract_origin_offset, IS_INFO, &abstract_origin_die, 0 )) + { + isinline = true; + name_die = abstract_origin_die; + } } + dwarf_highpc_b ( die, &h, 0, &formclass, 0 ); + dwarf_lowpc ( die, &l, 0 ); + if ( formclass == DW_FORM_CLASS_CONSTANT ) { h += l; @@ -1001,7 +1002,7 @@ char *symbolDisassembleLine( struct symbol *p, enum instructionClass *ic, symbol if ( !p->caphandle ) { /* Disassembler isn't initialised yet */ - if ( cs_open( CS_ARCH_ARM, CS_MODE_THUMB + CS_MODE_LITTLE_ENDIAN, &p->caphandle ) != CS_ERR_OK ) + if ( cs_open( CS_ARCH_ARM, CS_MODE_THUMB + CS_MODE_LITTLE_ENDIAN + CS_MODE_MCLASS, &p->caphandle ) != CS_ERR_OK ) { return NULL; } @@ -1044,6 +1045,14 @@ char *symbolDisassembleLine( struct symbol *p, enum instructionClass *ic, symbol && strstr( insn->op_str, "pc" ) ) ) ? LE_IC_JUMP : 0; + // create a copy to check for pc + char *copy = strdup(insn->op_str); + *ic |= ( + ( ( ( insn->id == ARM_INS_LDR ) ) + && strstr(strtok(copy,","), "pc" ) ) + ) ? LE_IC_JUMP : 0; + // free the copy + free(copy); /* Was it an exception return? */ *ic |= ( ( insn->id == ARM_INS_ERET ) ) ? LE_IC_JUMP | LE_IC_IRET : 0; @@ -1072,7 +1081,7 @@ char *symbolDisassembleLine( struct symbol *p, enum instructionClass *ic, symbol if ( newaddr ) { - *newaddr = detail->arm.operands[0].imm; + *newaddr = detail->arm.operands[n].imm; } break; From f0abfb86c0f0001604786fcf2e13bd6da0e476ac Mon Sep 17 00:00:00 2001 From: Lukas Date: Thu, 24 Oct 2024 11:14:29 +0200 Subject: [PATCH 4/6] update --- Src/loadelf.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Src/loadelf.c b/Src/loadelf.c index 511c14d0..1c2749fa 100644 --- a/Src/loadelf.c +++ b/Src/loadelf.c @@ -1045,14 +1045,14 @@ char *symbolDisassembleLine( struct symbol *p, enum instructionClass *ic, symbol && strstr( insn->op_str, "pc" ) ) ) ? LE_IC_JUMP : 0; - // create a copy to check for pc + /* create a copy to check if load in pc */ char *copy = strdup(insn->op_str); *ic |= ( ( ( ( insn->id == ARM_INS_LDR ) ) && strstr(strtok(copy,","), "pc" ) ) ) ? LE_IC_JUMP : 0; - // free the copy free(copy); + /* Was it an exception return? */ *ic |= ( ( insn->id == ARM_INS_ERET ) ) ? LE_IC_JUMP | LE_IC_IRET : 0; From 5f04cb4df5c5d38636802e2817c2f19766ae93b1 Mon Sep 17 00:00:00 2001 From: Lukas Date: Thu, 24 Oct 2024 11:14:36 +0200 Subject: [PATCH 5/6] loadelf fix could not find inline functions, LDR was missing --- Src/loadelf.c | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/Src/loadelf.c b/Src/loadelf.c index ea3295a1..1c2749fa 100644 --- a/Src/loadelf.c +++ b/Src/loadelf.c @@ -369,15 +369,16 @@ static void _processFunctionDie( struct symbol *p, Dwarf_Debug dbg, Dwarf_Die di attr_tag = DW_AT_abstract_origin; dwarf_attr( die, attr_tag, &attr_data, 0 ); dwarf_global_formref( attr_data, &abstract_origin_offset, 0 ); - dwarf_offdie_b( dbg, abstract_origin_offset, IS_INFO, &abstract_origin_die, 0 ); - isinline = true; - } - else - { - dwarf_highpc_b ( die, &h, 0, &formclass, 0 ); - dwarf_lowpc ( die, &l, 0 ); + if (DW_DLV_OK == dwarf_offdie_b( dbg, abstract_origin_offset, IS_INFO, &abstract_origin_die, 0 )) + { + isinline = true; + name_die = abstract_origin_die; + } } + dwarf_highpc_b ( die, &h, 0, &formclass, 0 ); + dwarf_lowpc ( die, &l, 0 ); + if ( formclass == DW_FORM_CLASS_CONSTANT ) { h += l; @@ -1001,7 +1002,7 @@ char *symbolDisassembleLine( struct symbol *p, enum instructionClass *ic, symbol if ( !p->caphandle ) { /* Disassembler isn't initialised yet */ - if ( cs_open( CS_ARCH_ARM, CS_MODE_THUMB + CS_MODE_LITTLE_ENDIAN, &p->caphandle ) != CS_ERR_OK ) + if ( cs_open( CS_ARCH_ARM, CS_MODE_THUMB + CS_MODE_LITTLE_ENDIAN + CS_MODE_MCLASS, &p->caphandle ) != CS_ERR_OK ) { return NULL; } @@ -1044,6 +1045,14 @@ char *symbolDisassembleLine( struct symbol *p, enum instructionClass *ic, symbol && strstr( insn->op_str, "pc" ) ) ) ? LE_IC_JUMP : 0; + /* create a copy to check if load in pc */ + char *copy = strdup(insn->op_str); + *ic |= ( + ( ( ( insn->id == ARM_INS_LDR ) ) + && strstr(strtok(copy,","), "pc" ) ) + ) ? LE_IC_JUMP : 0; + free(copy); + /* Was it an exception return? */ *ic |= ( ( insn->id == ARM_INS_ERET ) ) ? LE_IC_JUMP | LE_IC_IRET : 0; @@ -1072,7 +1081,7 @@ char *symbolDisassembleLine( struct symbol *p, enum instructionClass *ic, symbol if ( newaddr ) { - *newaddr = detail->arm.operands[0].imm; + *newaddr = detail->arm.operands[n].imm; } break; From ff18fc296e71a853bee455abc839b1c42a8be5c1 Mon Sep 17 00:00:00 2001 From: Lukas Date: Thu, 24 Oct 2024 16:45:33 +0200 Subject: [PATCH 6/6] _processFunctionDie fix --- Src/loadelf.c | 1 - 1 file changed, 1 deletion(-) diff --git a/Src/loadelf.c b/Src/loadelf.c index 1c2749fa..fc9e7c15 100644 --- a/Src/loadelf.c +++ b/Src/loadelf.c @@ -372,7 +372,6 @@ static void _processFunctionDie( struct symbol *p, Dwarf_Debug dbg, Dwarf_Die di if (DW_DLV_OK == dwarf_offdie_b( dbg, abstract_origin_offset, IS_INFO, &abstract_origin_die, 0 )) { isinline = true; - name_die = abstract_origin_die; } }