libdwarf
Using dwarf_srclines_b()

Example using dwarf_srclines_b()

An example calling dwarf_srclines_b

dwarf_srclines_dealloc_b dwarf_srclines_from_linecontext dwarf_srclines_files_indexes dwarf_srclines_files_data_b dwarf_srclines_two_level_from_linecontext

Parameters
pathPath to an object we wish to open.
errorAllows passing back error details to the caller.
Returns
Return DW_DLV_OK etc.
*/
int examplec(Dwarf_Die cu_die,Dwarf_Error *error)
{
/* EXAMPLE: DWARF2-DWARF5 access. */
Dwarf_Line *linebuf = 0;
Dwarf_Signed linecount = 0;
Dwarf_Line *linebuf_actuals = 0;
Dwarf_Signed linecount_actuals = 0;
Dwarf_Line_Context line_context = 0;
Dwarf_Small table_count = 0;
Dwarf_Unsigned lineversion = 0;
int sres = 0;
/* ... */
/* we use 'return' here to signify we can do nothing more
at this point in the code. */
sres = dwarf_srclines_b(cu_die,&lineversion,
&table_count,&line_context,error);
if (sres != DW_DLV_OK) {
/* Handle the DW_DLV_NO_ENTRY or DW_DLV_ERROR
No memory was allocated so there nothing
to dealloc here. */
return sres;
}
if (table_count == 0) {
/* A line table with no actual lines. */
/*...do something, see dwarf_srclines_files_count()
etc below. */
dwarf_srclines_dealloc_b(line_context);
/* All the memory is released, the line_context
and linebuf zeroed now
as a reminder they are stale. */
linebuf = 0;
line_context = 0;
} else if (table_count == 1) {
Dwarf_Signed i = 0;
Dwarf_Signed baseindex = 0;
Dwarf_Signed file_count = 0;
Dwarf_Signed endindex = 0;
/* Standard dwarf 2,3,4, or 5 line table */
/* Do something. */
/* First let us index through all the files listed
in the line table header. */
sres = dwarf_srclines_files_indexes(line_context,
&baseindex,&file_count,&endindex,error);
if (sres != DW_DLV_OK) {
/* Something badly wrong! */
return sres;
}
/* Works for DWARF2,3,4 (one-based index)
and DWARF5 (zero-based index) */
for (i = baseindex; i < endindex; i++) {
Dwarf_Unsigned dirindex = 0;
Dwarf_Unsigned modtime = 0;
Dwarf_Unsigned flength = 0;
Dwarf_Form_Data16 *md5data = 0;
int vres = 0;
const char *name = 0;
vres = dwarf_srclines_files_data_b(line_context,i,
&name,&dirindex, &modtime,&flength,
&md5data,error);
if (vres != DW_DLV_OK) {
/* something very wrong. */
return vres;
}
/* do something */
}
/* For this case where we have a line table we will likely
wish to get the line details: */
sres = dwarf_srclines_from_linecontext(line_context,
&linebuf,&linecount,
error);
if (sres != DW_DLV_OK) {
/* Error. Clean up the context information. */
dwarf_srclines_dealloc_b(line_context);
return sres;
}
/* The lines are normal line table lines. */
for (i = 0; i < linecount; ++i) {
/* use linebuf[i] */
}
dwarf_srclines_dealloc_b(line_context);
/* All the memory is released, the line_context
and linebuf zeroed now as a reminder they are stale */
linebuf = 0;
line_context = 0;
linecount = 0;
} else {
Dwarf_Signed i = 0;
/* ASSERT: table_count == 2,
Experimental two-level line table. Version 0xf006
We do not define the meaning of this non-standard
set of tables here. */
/* For 'something C' (two-level line tables)
one codes something like this
Note that we do not define the meaning or
use of two-level line
tables as these are experimental, not standard DWARF. */
&linebuf,&linecount,
&linebuf_actuals,&linecount_actuals,
error);
if (sres == DW_DLV_OK) {
for (i = 0; i < linecount; ++i) {
/* use linebuf[i], these are the 'logicals'
entries. */
}
for (i = 0; i < linecount_actuals; ++i) {
/* use linebuf_actuals[i], these are the
actuals entries */
}
dwarf_srclines_dealloc_b(line_context);
line_context = 0;
linebuf = 0;
linecount = 0;
linebuf_actuals = 0;
linecount_actuals = 0;
} else if (sres == DW_DLV_NO_ENTRY) {
/* This should be impossible, but do something. */
/* Then Free the line_context */
dwarf_srclines_dealloc_b(line_context);
line_context = 0;
linebuf = 0;
linecount = 0;
linebuf_actuals = 0;
linecount_actuals = 0;
} else {
/* ERROR, show the error or something.
Free the line_context. */
dwarf_srclines_dealloc_b(line_context);
line_context = 0;
linebuf = 0;
linecount = 0;
linebuf_actuals = 0;
linecount_actuals = 0;
}
}
return DW_DLV_OK;
}
struct Dwarf_Die_s * Dwarf_Die
Definition: libdwarf.h:608
struct Dwarf_Line_s * Dwarf_Line
Definition: libdwarf.h:619
struct Dwarf_Error_s * Dwarf_Error
Definition: libdwarf.h:597
struct Dwarf_Line_Context_s * Dwarf_Line_Context
Definition: libdwarf.h:697
unsigned char Dwarf_Small
Definition: libdwarf.h:204
signed long long Dwarf_Signed
Definition: libdwarf.h:197
unsigned long long Dwarf_Unsigned
Definition: libdwarf.h:196
int dwarf_srclines_files_indexes(Dwarf_Line_Context dw_context, Dwarf_Signed *dw_baseindex, Dwarf_Signed *dw_count, Dwarf_Signed *dw_endindex, Dwarf_Error *dw_error)
Return values easing indexing line table file numbers. Count is the real count of files array entries...
int dwarf_srclines_two_level_from_linecontext(Dwarf_Line_Context dw_context, Dwarf_Line **dw_linebuf, Dwarf_Signed *dw_linecount, Dwarf_Line **dw_linebuf_actuals, Dwarf_Signed *dw_linecount_actuals, Dwarf_Error *dw_error)
Returns line table counts and data.
void dwarf_srclines_dealloc_b(Dwarf_Line_Context dw_context)
Dealloc the memory allocated by dwarf_srclines_b.
int dwarf_srclines_b(Dwarf_Die dw_cudie, Dwarf_Unsigned *dw_version_out, Dwarf_Small *dw_table_count, Dwarf_Line_Context *dw_linecontext, Dwarf_Error *dw_error)
Initialize Dwarf_Line_Context for line table access.
int dwarf_srclines_from_linecontext(Dwarf_Line_Context dw_linecontext, Dwarf_Line **dw_linebuf, Dwarf_Signed *dw_linecount, Dwarf_Error *dw_error)
Access source lines from line context.
int dwarf_srclines_files_data_b(Dwarf_Line_Context dw_context, Dwarf_Signed dw_index_in, const char **dw_name, Dwarf_Unsigned *dw_directory_index, Dwarf_Unsigned *dw_last_mod_time, Dwarf_Unsigned *dw_file_length, Dwarf_Form_Data16 **dw_md5ptr, Dwarf_Error *dw_error)
Access data for each line table file.
Definition: libdwarf.h:302