Skip to content

Commit a71cca0

Browse files
committed
Bug Fix: Wrong First Breakpoint in Clang
1 parent b62607d commit a71cca0

File tree

4 files changed

+14
-11
lines changed

4 files changed

+14
-11
lines changed

src/analysis.c

+8-8
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,7 @@ void static_analysis_finish(void)
626626
* does, but in a 'smarter' way.
627627
*/
628628
struct hashtable *static_analysis(const char *file, const char *func,
629-
struct array *lines_l)
629+
struct array *lines_l, uint64_t firstbreak)
630630
{
631631
char *file_cur;
632632
struct dw_line *line;
@@ -650,15 +650,15 @@ struct hashtable *static_analysis(const char *file, const char *func,
650650
/* Initialize breakpoint hashtable. */
651651
hashtable_init(&breakpoints, NULL);
652652

653-
/* First line. */
654-
line = array_get(&lines_l, 0, NULL);
655-
func_line_start = line->line_no;
656-
657-
/* Allocate our first breakpoint. */
653+
/*
654+
* Allocate our first breakpoint to the first function
655+
* instruction. Since this is an special case, there is
656+
* no need to known the line number.
657+
*/
658658
b = malloc(sizeof(struct breakpoint));
659-
b->addr = line->addr;
659+
b->addr = firstbreak;
660660
b->original_byte = 0;
661-
b->line_no = line->line_no;
661+
b->line_no = 0;
662662

663663
/*
664664
* Set our first breakpoint to the very

src/include/analysis.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@
5252
extern struct hashtable *static_analysis(
5353
const char *file,
5454
const char *func,
55-
struct array *lines);
55+
struct array *lines,
56+
uint64_t firstbreak);
5657

5758

5859
#endif /* ANALYSIS_H */

src/main.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ void do_analysis(const char *file, const char *function, char **argv)
198198
* - Static analysis
199199
*/
200200
breakpoints = (args.flags & FLG_STATIC_ANALYSIS) ?
201-
static_analysis(filename, function, lines) :
201+
static_analysis(filename, function, lines, dw.dw_func.low_pc) :
202202
bp_createlist(lines);
203203

204204
/* Insert them. */
@@ -372,7 +372,7 @@ static void dump_all(const char *prg_name)
372372
/* Break point list. */
373373
printf("\nBreakpoint list:\n");
374374
breakpoints = (args.flags & FLG_STATIC_ANALYSIS) ?
375-
static_analysis(filename, args.function, lines) :
375+
static_analysis(filename, args.function, lines, dw.dw_func.low_pc) :
376376
bp_createlist(lines);
377377

378378
i = 0;

src/tests/run-tests.sh

+2
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ then
9999
echo -e " [${RED}NOT PASSED${NC}] (normal analysis differ from expected output)"
100100
exit 1
101101
fi
102+
else
103+
echo -e " [${RED}NOT PASSED${NC}] (execution error)"
102104
fi
103105

104106
# Run static analysis tests

0 commit comments

Comments
 (0)