Skip to content

Commit 59473f7

Browse files
libbacktrace: pass -1 to error callback for unrecognized DWARF
PR libbacktrace/98818 * dwarf.c (dwarf_buf_error): Add errnum parameter. Change all callers. * backtrace.h: Update backtrace_error_callback comment.
1 parent 7854b0b commit 59473f7

File tree

2 files changed

+43
-30
lines changed

2 files changed

+43
-30
lines changed

backtrace.h

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,14 @@ struct backtrace_state;
5454
invalid after this function returns.
5555
5656
As a special case, the ERRNUM argument will be passed as -1 if no
57-
debug info can be found for the executable, but the function
58-
requires debug info (e.g., backtrace_full, backtrace_pcinfo). The
59-
MSG in this case will be something along the lines of "no debug
60-
info". Similarly, ERRNUM will be passed as -1 if there is no
61-
symbol table, but the function requires a symbol table (e.g.,
62-
backtrace_syminfo). This may be used as a signal that some other
63-
approach should be tried. */
57+
debug info can be found for the executable, or if the debug info
58+
exists but has an unsupported version, but the function requires
59+
debug info (e.g., backtrace_full, backtrace_pcinfo). The MSG in
60+
this case will be something along the lines of "no debug info".
61+
Similarly, ERRNUM will be passed as -1 if there is no symbol table,
62+
but the function requires a symbol table (e.g., backtrace_syminfo).
63+
This may be used as a signal that some other approach should be
64+
tried. */
6465

6566
typedef void (*backtrace_error_callback) (void *data, const char *msg,
6667
int errnum);

dwarf.c

Lines changed: 35 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -743,13 +743,13 @@ struct dwarf_data
743743
/* Report an error for a DWARF buffer. */
744744

745745
static void
746-
dwarf_buf_error (struct dwarf_buf *buf, const char *msg)
746+
dwarf_buf_error (struct dwarf_buf *buf, const char *msg, int errnum)
747747
{
748748
char b[200];
749749

750750
snprintf (b, sizeof b, "%s in %s at %d",
751751
msg, buf->name, (int) (buf->buf - buf->start));
752-
buf->error_callback (buf->data, b, 0);
752+
buf->error_callback (buf->data, b, errnum);
753753
}
754754

755755
/* Require at least COUNT bytes in BUF. Return 1 if all is well, 0 on
@@ -763,7 +763,7 @@ require (struct dwarf_buf *buf, size_t count)
763763

764764
if (!buf->reported_underflow)
765765
{
766-
dwarf_buf_error (buf, "DWARF underflow");
766+
dwarf_buf_error (buf, "DWARF underflow", 0);
767767
buf->reported_underflow = 1;
768768
}
769769

@@ -925,7 +925,7 @@ read_address (struct dwarf_buf *buf, int addrsize)
925925
case 8:
926926
return read_uint64 (buf);
927927
default:
928-
dwarf_buf_error (buf, "unrecognized address size");
928+
dwarf_buf_error (buf, "unrecognized address size", 0);
929929
return 0;
930930
}
931931
}
@@ -976,7 +976,7 @@ read_uleb128 (struct dwarf_buf *buf)
976976
ret |= ((uint64_t) (b & 0x7f)) << shift;
977977
else if (!overflow)
978978
{
979-
dwarf_buf_error (buf, "LEB128 overflows uint64_t");
979+
dwarf_buf_error (buf, "LEB128 overflows uint64_t", 0);
980980
overflow = 1;
981981
}
982982
shift += 7;
@@ -1011,7 +1011,7 @@ read_sleb128 (struct dwarf_buf *buf)
10111011
val |= ((uint64_t) (b & 0x7f)) << shift;
10121012
else if (!overflow)
10131013
{
1014-
dwarf_buf_error (buf, "signed LEB128 overflows uint64_t");
1014+
dwarf_buf_error (buf, "signed LEB128 overflows uint64_t", 0);
10151015
overflow = 1;
10161016
}
10171017
shift += 7;
@@ -1151,7 +1151,7 @@ read_attribute (enum dwarf_form form, uint64_t implicit_val,
11511151
offset = read_offset (buf, is_dwarf64);
11521152
if (offset >= dwarf_sections->size[DEBUG_STR])
11531153
{
1154-
dwarf_buf_error (buf, "DW_FORM_strp out of range");
1154+
dwarf_buf_error (buf, "DW_FORM_strp out of range", 0);
11551155
return 0;
11561156
}
11571157
val->encoding = ATTR_VAL_STRING;
@@ -1166,7 +1166,7 @@ read_attribute (enum dwarf_form form, uint64_t implicit_val,
11661166
offset = read_offset (buf, is_dwarf64);
11671167
if (offset >= dwarf_sections->size[DEBUG_LINE_STR])
11681168
{
1169-
dwarf_buf_error (buf, "DW_FORM_line_strp out of range");
1169+
dwarf_buf_error (buf, "DW_FORM_line_strp out of range", 0);
11701170
return 0;
11711171
}
11721172
val->encoding = ATTR_VAL_STRING;
@@ -1213,7 +1213,8 @@ read_attribute (enum dwarf_form form, uint64_t implicit_val,
12131213
if (form == DW_FORM_implicit_const)
12141214
{
12151215
dwarf_buf_error (buf,
1216-
"DW_FORM_indirect to DW_FORM_implicit_const");
1216+
"DW_FORM_indirect to DW_FORM_implicit_const",
1217+
0);
12171218
return 0;
12181219
}
12191220
return read_attribute ((enum dwarf_form) form, 0, buf, is_dwarf64,
@@ -1346,7 +1347,7 @@ read_attribute (enum dwarf_form form, uint64_t implicit_val,
13461347
}
13471348
if (offset >= altlink->dwarf_sections.size[DEBUG_STR])
13481349
{
1349-
dwarf_buf_error (buf, "DW_FORM_strp_sup out of range");
1350+
dwarf_buf_error (buf, "DW_FORM_strp_sup out of range", 0);
13501351
return 0;
13511352
}
13521353
val->encoding = ATTR_VAL_STRING;
@@ -1355,7 +1356,7 @@ read_attribute (enum dwarf_form form, uint64_t implicit_val,
13551356
return 1;
13561357
}
13571358
default:
1358-
dwarf_buf_error (buf, "unrecognized DWARF form");
1359+
dwarf_buf_error (buf, "unrecognized DWARF form", -1);
13591360
return 0;
13601361
}
13611362
}
@@ -1404,7 +1405,9 @@ resolve_string (const struct dwarf_sections *dwarf_sections, int is_dwarf64,
14041405
offset = read_offset (&offset_buf, is_dwarf64);
14051406
if (offset >= dwarf_sections->size[DEBUG_STR])
14061407
{
1407-
dwarf_buf_error (&offset_buf, "DW_FORM_strx offset out of range");
1408+
dwarf_buf_error (&offset_buf,
1409+
"DW_FORM_strx offset out of range",
1410+
0);
14081411
return 0;
14091412
}
14101413
*string = (const char *) dwarf_sections->data[DEBUG_STR] + offset;
@@ -2212,7 +2215,7 @@ add_ranges_from_rnglists (
22122215
break;
22132216

22142217
default:
2215-
dwarf_buf_error (&rnglists_buf, "unrecognized DW_RLE value");
2218+
dwarf_buf_error (&rnglists_buf, "unrecognized DW_RLE value", -1);
22162219
return 0;
22172220
}
22182221
}
@@ -2479,7 +2482,7 @@ build_address_map (struct backtrace_state *state, uintptr_t base_address,
24792482
version = read_uint16 (&unit_buf);
24802483
if (version < 2 || version > 5)
24812484
{
2482-
dwarf_buf_error (&unit_buf, "unrecognized DWARF version");
2485+
dwarf_buf_error (&unit_buf, "unrecognized DWARF version", -1);
24832486
goto fail;
24842487
}
24852488

@@ -2758,7 +2761,8 @@ read_v2_paths (struct backtrace_state *state, struct unit *u,
27582761
{
27592762
dwarf_buf_error (hdr_buf,
27602763
("invalid directory index in "
2761-
"line number program header"));
2764+
"line number program header"),
2765+
0);
27622766
return 0;
27632767
}
27642768
dir_len = strlen (dir);
@@ -2827,7 +2831,8 @@ read_lnct (struct backtrace_state *state, struct dwarf_data *ddata,
28272831
{
28282832
dwarf_buf_error (hdr_buf,
28292833
("invalid directory index in "
2830-
"line number program header"));
2834+
"line number program header"),
2835+
0);
28312836
return 0;
28322837
}
28332838
dir = hdr->dirs[val.u.uint];
@@ -2842,7 +2847,8 @@ read_lnct (struct backtrace_state *state, struct dwarf_data *ddata,
28422847
if (path == NULL)
28432848
{
28442849
dwarf_buf_error (hdr_buf,
2845-
"missing file name in line number program header");
2850+
"missing file name in line number program header",
2851+
0);
28462852
return 0;
28472853
}
28482854

@@ -2969,7 +2975,7 @@ read_line_header (struct backtrace_state *state, struct dwarf_data *ddata,
29692975
hdr->version = read_uint16 (line_buf);
29702976
if (hdr->version < 2 || hdr->version > 5)
29712977
{
2972-
dwarf_buf_error (line_buf, "unsupported line number version");
2978+
dwarf_buf_error (line_buf, "unsupported line number version", -1);
29732979
return 0;
29742980
}
29752981

@@ -2983,7 +2989,8 @@ read_line_header (struct backtrace_state *state, struct dwarf_data *ddata,
29832989
if (read_byte (line_buf) != 0)
29842990
{
29852991
dwarf_buf_error (line_buf,
2986-
"non-zero segment_selector_size not supported");
2992+
"non-zero segment_selector_size not supported",
2993+
-1);
29872994
return 0;
29882995
}
29892996
}
@@ -3124,7 +3131,8 @@ read_line_program (struct backtrace_state *state, struct dwarf_data *ddata,
31243131
{
31253132
dwarf_buf_error (line_buf,
31263133
("invalid directory index "
3127-
"in line number program"));
3134+
"in line number program"),
3135+
0);
31283136
return 0;
31293137
}
31303138
dir_len = strlen (dir);
@@ -3190,7 +3198,8 @@ read_line_program (struct backtrace_state *state, struct dwarf_data *ddata,
31903198
{
31913199
dwarf_buf_error (line_buf,
31923200
("invalid file number in "
3193-
"line number program"));
3201+
"line number program"),
3202+
0);
31943203
return 0;
31953204
}
31963205
filename = hdr->filenames[fileno];
@@ -3425,7 +3434,9 @@ read_referenced_name (struct dwarf_data *ddata, struct unit *u,
34253434
code = read_uleb128 (&unit_buf);
34263435
if (code == 0)
34273436
{
3428-
dwarf_buf_error (&unit_buf, "invalid abstract origin or specification");
3437+
dwarf_buf_error (&unit_buf,
3438+
"invalid abstract origin or specification",
3439+
0);
34293440
return NULL;
34303441
}
34313442

@@ -3628,7 +3639,8 @@ read_function_entry (struct backtrace_state *state, struct dwarf_data *ddata,
36283639
{
36293640
dwarf_buf_error (unit_buf,
36303641
("invalid file number in "
3631-
"DW_AT_call_file attribute"));
3642+
"DW_AT_call_file attribute"),
3643+
0);
36323644
return 0;
36333645
}
36343646
function->caller_filename =

0 commit comments

Comments
 (0)