From 5eb3552ee7822d7a1c7126144af7aa89b927994a Mon Sep 17 00:00:00 2001 From: Dave Marples Date: Sun, 30 Jul 2023 23:00:06 +0100 Subject: [PATCH] Fixes for linux --- README.md | 5 +---- Src/getline.c | 54 +++++++++++++++++++++++++++++++++++++-------------- Src/loadelf.c | 24 +++++++++-------------- meson.build | 2 +- 4 files changed, 50 insertions(+), 35 deletions(-) diff --git a/README.md b/README.md index bff503a6..4d2f79b1 100644 --- a/README.md +++ b/README.md @@ -242,12 +242,9 @@ Dependencies * libczmq-dev * ncurses * libsdl -* libdw-dev * libelf-dev * libcapstone-dev -Note that `objdump` version at least 2.33.1 is also required. By default the suite will run `arm-none-eabi-objdump` but another binary or pathname can be subsituted via the OBJDUMP environment variable. - Build ----- @@ -261,7 +258,7 @@ If you do want to build the system, then the command line to build the Orbuculum >ninja -C build ``` -You may need to change the paths to your libusb files, depending on how well your build environment is set up. +You may need to change the paths to your libusb files, depending on how well your build environment is set up. It's also worth noting that Ubuntu comes with a pretty old version of meson so if you get errors you may need to install a more recent one via pip. Permissions and Access ---------------------- diff --git a/Src/getline.c b/Src/getline.c index 885f2a3d..81c0f81e 100644 --- a/Src/getline.c +++ b/Src/getline.c @@ -3,49 +3,73 @@ #include #include -size_t getline(char **lineptr, size_t *n, FILE *stream) { +size_t getline( char **lineptr, size_t *n, FILE *stream ) +{ char *bufptr = NULL; char *p = bufptr; size_t size; int c; - if (lineptr == NULL) { + if ( lineptr == NULL ) + { return -1; } - if (stream == NULL) { + + if ( stream == NULL ) + { return -1; } - if (n == NULL) { + + if ( n == NULL ) + { return -1; } + bufptr = *lineptr; size = *n; - c = fgetc(stream); - if (c == EOF) { + c = fgetc( stream ); + + if ( c == EOF ) + { return -1; } - if (bufptr == NULL) { - bufptr = malloc(128); - if (bufptr == NULL) { + + if ( bufptr == NULL ) + { + bufptr = malloc( 128 ); + + if ( bufptr == NULL ) + { return -1; } + size = 128; } + p = bufptr; - while(c != EOF) { - if ((p - bufptr) > (size - 1)) { + + while ( c != EOF ) + { + if ( ( p - bufptr ) > ( size - 1 ) ) + { size = size + 128; - bufptr = realloc(bufptr, size); - if (bufptr == NULL) { + bufptr = realloc( bufptr, size ); + + if ( bufptr == NULL ) + { return -1; } } + *p++ = c; - if (c == '\n') { + + if ( c == '\n' ) + { break; } - c = fgetc(stream); + + c = fgetc( stream ); } *p++ = '\0'; diff --git a/Src/loadelf.c b/Src/loadelf.c index 84d1871e..a044744f 100644 --- a/Src/loadelf.c +++ b/Src/loadelf.c @@ -12,7 +12,7 @@ #include "generics.h" #if defined(WIN32) -extern size_t getline(char **lineptr, size_t *n, FILE *stream); + extern size_t getline( char **lineptr, size_t *n, FILE *stream ); #endif #define MAX_LINE_LEN (4095) @@ -250,7 +250,7 @@ static void _dump_die_attribs( Dwarf_Debug dbg, Dwarf_Die die ) } dwarf_get_AT_name( attr, &name ); - printf( "Attribute Name: %s\n", name ); + fprintf( stderr, "Attribute Name: %s\n", name ); } // Free attribute list @@ -278,11 +278,6 @@ static void _getSourceLines( struct symbol *p, Dwarf_Debug dbg, Dwarf_Die die ) Dwarf_Bool begin; Dwarf_Bool isset; - //Dwarf_Bool ispend; - //Dwarf_Bool ispbegin; - //Dwarf_Unsigned isa; - //Dwarf_Unsigned disc; - /* Now, for each source line, pull it into the line storage */ if ( DW_DLV_OK == dwarf_srclines_b( die, &version, &tc, &linecontext, 0 ) ) { @@ -313,12 +308,12 @@ static void _getSourceLines( struct symbol *p, Dwarf_Debug dbg, Dwarf_Die die ) if ( ( zero_start_dont_store && ( ( !begin ) || ( !line_addr ) || ( ( line_addr - tracked_addr ) < 16 ) ) ) ) { zero_start_dont_store = true; - // printf("!"); + // printf("!"); } else { /* We are going to store this one */ - //if (zero_start_dont_store) printf("\n%08x: ",(uint32_t)line_addr); + // if (zero_start_dont_store) printf("\n%08x: ",(uint32_t)line_addr); //else printf("*"); zero_start_dont_store = false; dwarf_lineno( linebuf[i], &line_num, 0 ); @@ -476,7 +471,7 @@ static bool _readLines( int fd, struct symbol *p ) Dwarf_Addr cu_low_addr; Dwarf_Half address_size; Dwarf_Unsigned next_cu_header = 0; - Dwarf_Die cu_die; + Dwarf_Die cu_die; bool retval = false; Dwarf_Half dw_length_size; @@ -518,9 +513,11 @@ static bool _readLines( int fd, struct symbol *p ) /* 1: Collect the functions and lines */ /* ---------------------------------- */ - while ( ( 0 == dwarf_next_cu_header_d( dbg, 0, &cu_header_length, &version_stamp, &abbrev_offset, &address_size, &dw_length_size, &dw_extension_size, &dw_type_signature, &dw_typeoffset, &next_cu_header, &dw_header_cu_type, &err ) ) ) + while ( ( 0 == dwarf_next_cu_header_d( dbg, true, &cu_header_length, &version_stamp, &abbrev_offset, &address_size, &dw_length_size, &dw_extension_size, &dw_type_signature, &dw_typeoffset, + &next_cu_header, &dw_header_cu_type, &err ) ) ) { - dwarf_siblingof_b( dbg, NULL, 0, &cu_die, &err ); + dwarf_siblingof_b( dbg, NULL, true, &cu_die, &err ); + dwarf_diename( cu_die, &name, 0 ); dwarf_die_text( cu_die, DW_AT_producer, &producer, 0 ); dwarf_die_text( cu_die, DW_AT_comp_dir, &compdir, 0 ); @@ -565,9 +562,6 @@ static bool _readLines( int fd, struct symbol *p ) p->nlines--; } - - /* Now set the high extent address to one less than the low address of the following line */ - // p->line[i-1]->highaddr = p->line[i]->lowaddr-1; } /* Now do the same for lines with the same line number and file */ diff --git a/meson.build b/meson.build index e67937a8..a597141d 100644 --- a/meson.build +++ b/meson.build @@ -1,5 +1,5 @@ -project('orbuculum', 'c', meson_version: '>=0.63') +project('orbuculum', 'c', version:'2.1.0', meson_version: '>=0.63') uicolours_default = declare_dependency(compile_args: ['-include', 'uicolours_default.h']) if host_machine.system() == 'windows'