diff --git a/src/dbginfo/dbginfo.c b/src/dbginfo/dbginfo.c index 8ca20a87f..1fc3d48fe 100644 --- a/src/dbginfo/dbginfo.c +++ b/src/dbginfo/dbginfo.c @@ -4458,8 +4458,9 @@ static void ProcessSpanInfo (InputData* D) static void ProcessSymInfo (InputData* D) /* Postprocess symbol infos */ { + unsigned I, J; + /* Walk over the symbols and resolve the references */ - unsigned I; for (I = 0; I < CollCount (&D->Info->SymInfoById); ++I) { /* Get the symbol info */ @@ -4531,6 +4532,47 @@ static void ProcessSymInfo (InputData* D) } CollAppend (S->Parent.Info->CheapLocals, S); } + + /* Resolve the line infos for the symbol definition */ + for (J = 0; I < CollCount (&S->DefLineInfoList); ++J) { + + /* Get the id of this line info */ + unsigned LineId = CollIdAt (&S->DefLineInfoList, J); + if (LineId >= CollCount (&D->Info->LineInfoById)) { + ParseError (D, + CC65_ERROR, + "Invalid line id %u for symbol with id %u", + LineId, S->Id); + CollReplace (&S->DefLineInfoList, 0, J); + } else { + /* Get a pointer to the line info */ + LineInfo* LI = CollAt (&D->Info->LineInfoById, LineId); + + /* Replace the id by the pointer */ + CollReplace (&S->DefLineInfoList, LI, J); + } + } + + /* Resolve the line infos for symbol references */ + for (J = 0; I < CollCount (&S->RefLineInfoList); ++J) { + + /* Get the id of this line info */ + unsigned LineId = CollIdAt (&S->RefLineInfoList, J); + if (LineId >= CollCount (&D->Info->LineInfoById)) { + ParseError (D, + CC65_ERROR, + "Invalid line id %u for symbol with id %u", + LineId, S->Id); + CollReplace (&S->RefLineInfoList, 0, J); + } else { + /* Get a pointer to the line info */ + LineInfo* LI = CollAt (&D->Info->LineInfoById, LineId); + + /* Replace the id by the pointer */ + CollReplace (&S->RefLineInfoList, LI, J); + } + } + } /* Second run. Resolve scopes for cheap locals */ @@ -4983,6 +5025,84 @@ const cc65_lineinfo* cc65_line_bysource (cc65_dbginfo Handle, unsigned FileId) +const cc65_lineinfo* cc65_line_bysymdef (cc65_dbginfo Handle, unsigned SymId) +/* Return line information for the definition of a symbol. The function + * returns NULL if the symbol id is invalid, otherwise a list of line infos. + */ +{ + DbgInfo* Info; + SymInfo* S; + cc65_lineinfo* D; + unsigned I; + + /* Check the parameter */ + assert (Handle != 0); + + /* The handle is actually a pointer to a debug info struct */ + Info = (DbgInfo*) Handle; + + /* Check if the symbol id is valid */ + if (SymId >= CollCount (&Info->SymInfoById)) { + return 0; + } + + /* Get the symbol */ + S = CollAt (&Info->SymInfoById, SymId); + + /* Prepare the struct we will return to the caller */ + D = new_cc65_lineinfo (CollCount (&S->DefLineInfoList)); + + /* Fill in the data */ + for (I = 0; I < CollCount (&S->DefLineInfoList); ++I) { + /* Copy the data */ + CopyLineInfo (D->data + I, CollConstAt (&S->DefLineInfoList, I)); + } + + /* Return the allocated struct */ + return D; +} + + + +const cc65_lineinfo* cc65_line_bysymref (cc65_dbginfo Handle, unsigned SymId) +/* Return line information for all references of a symbol. The function + * returns NULL if the symbol id is invalid, otherwise a list of line infos. + */ +{ + DbgInfo* Info; + SymInfo* S; + cc65_lineinfo* D; + unsigned I; + + /* Check the parameter */ + assert (Handle != 0); + + /* The handle is actually a pointer to a debug info struct */ + Info = (DbgInfo*) Handle; + + /* Check if the symbol id is valid */ + if (SymId >= CollCount (&Info->SymInfoById)) { + return 0; + } + + /* Get the symbol */ + S = CollAt (&Info->SymInfoById, SymId); + + /* Prepare the struct we will return to the caller */ + D = new_cc65_lineinfo (CollCount (&S->RefLineInfoList)); + + /* Fill in the data */ + for (I = 0; I < CollCount (&S->RefLineInfoList); ++I) { + /* Copy the data */ + CopyLineInfo (D->data + I, CollConstAt (&S->RefLineInfoList, I)); + } + + /* Return the allocated struct */ + return D; +} + + + void cc65_free_lineinfo (cc65_dbginfo Handle, const cc65_lineinfo* Info) /* Free line info returned by one of the other functions */ { diff --git a/src/dbginfo/dbginfo.h b/src/dbginfo/dbginfo.h index 664966f48..04eff93d8 100644 --- a/src/dbginfo/dbginfo.h +++ b/src/dbginfo/dbginfo.h @@ -194,6 +194,16 @@ const cc65_lineinfo* cc65_line_bysource (cc65_dbginfo Handle, unsigned source_id * file id is invalid. */ +const cc65_lineinfo* cc65_line_bysymdef (cc65_dbginfo handle, unsigned symbol_id); +/* Return line information for the definition of a symbol. The function + * returns NULL if the symbol id is invalid, otherwise a list of line infos. + */ + +const cc65_lineinfo* cc65_line_bysymref (cc65_dbginfo handle, unsigned symbol_id); +/* Return line information for all references of a symbol. The function + * returns NULL if the symbol id is invalid, otherwise a list of line infos. + */ + void cc65_free_lineinfo (cc65_dbginfo handle, const cc65_lineinfo* info); /* Free line info returned by one of the other functions */ @@ -205,7 +215,7 @@ void cc65_free_lineinfo (cc65_dbginfo handle, const cc65_lineinfo* info); -/* Module information +/* Module information * Notes: * - scope_id contains CC65_INV_ID if the module was compiled without * debug information.