From 7ee90fb21bed985d4d1c58d982a270a5cda09b39 Mon Sep 17 00:00:00 2001 From: uz Date: Fri, 19 Aug 2011 14:39:11 +0000 Subject: [PATCH] Added cc65_line_byspan and cc65_scope_byspan. git-svn-id: svn://svn.cc65.org/cc65/trunk@5230 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- src/dbginfo/dbginfo.c | 84 ++++++++++++++++++++++++++++++++++++++++++- src/dbginfo/dbginfo.h | 10 ++++++ 2 files changed, 93 insertions(+), 1 deletion(-) diff --git a/src/dbginfo/dbginfo.c b/src/dbginfo/dbginfo.c index 60a813798..46117abb3 100644 --- a/src/dbginfo/dbginfo.c +++ b/src/dbginfo/dbginfo.c @@ -1486,7 +1486,7 @@ static void CopySpanInfo (cc65_spandata* D, const SpanInfo* S) } else { D->scope_count = 0; } - if (S->LineInfoList) { + if (S->LineInfoList) { D->line_count = CollCount (S->LineInfoList); } else { D->line_count = 0; @@ -5098,6 +5098,47 @@ const cc65_lineinfo* cc65_line_bysymref (cc65_dbginfo Handle, unsigned SymId) +const cc65_lineinfo* cc65_line_byspan (cc65_dbginfo Handle, unsigned SpanId) +/* Return line information for a a span. The function returns NULL if the + * span id is invalid, otherwise a list of line infos. + */ +{ + const DbgInfo* Info; + const SpanInfo* S; + cc65_lineinfo* D; + unsigned I; + + /* Check the parameter */ + assert (Handle != 0); + + /* The handle is actually a pointer to a debug info struct */ + Info = Handle; + + /* Check if the span id is valid */ + if (SpanId >= CollCount (&Info->SpanInfoById)) { + return 0; + } + + /* Get the span */ + S = CollAt (&Info->SpanInfoById, SpanId); + + /* Prepare the struct we will return to the caller */ + D = new_cc65_lineinfo (S->LineInfoList? CollCount (S->LineInfoList) : 0); + + /* Fill in the data. Since D->LineInfoList may be NULL, we will use the + * count field of the returned data struct instead. + */ + for (I = 0; I < D->count; ++I) { + /* Copy the data */ + CopyLineInfo (D->data + I, CollAt (S->LineInfoList, 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 */ { @@ -5991,6 +6032,47 @@ const cc65_scopeinfo* cc65_scope_byname (cc65_dbginfo Handle, const char* Name) +const cc65_scopeinfo* cc65_scope_byspan (cc65_dbginfo Handle, unsigned SpanId) +/* Return scope information for a a span. The function returns NULL if the + * span id is invalid, otherwise a list of line scopes. + */ +{ + const DbgInfo* Info; + const SpanInfo* S; + cc65_scopeinfo* D; + unsigned I; + + /* Check the parameter */ + assert (Handle != 0); + + /* The handle is actually a pointer to a debug info struct */ + Info = Handle; + + /* Check if the span id is valid */ + if (SpanId >= CollCount (&Info->SpanInfoById)) { + return 0; + } + + /* Get the span */ + S = CollAt (&Info->SpanInfoById, SpanId); + + /* Prepare the struct we will return to the caller */ + D = new_cc65_scopeinfo (S->ScopeInfoList? CollCount (S->ScopeInfoList) : 0); + + /* Fill in the data. Since D->ScopeInfoList may be NULL, we will use the + * count field of the returned data struct instead. + */ + for (I = 0; I < D->count; ++I) { + /* Copy the data */ + CopyScopeInfo (D->data + I, CollAt (S->ScopeInfoList, I)); + } + + /* Return the allocated struct */ + return D; +} + + + const cc65_scopeinfo* cc65_childscopes_byid (cc65_dbginfo Handle, unsigned Id) /* Return the direct child scopes of a scope with a given id. The function * returns NULL if no scope with this id was found, otherwise a list of the diff --git a/src/dbginfo/dbginfo.h b/src/dbginfo/dbginfo.h index 42edec502..aa38e29a0 100644 --- a/src/dbginfo/dbginfo.h +++ b/src/dbginfo/dbginfo.h @@ -204,6 +204,11 @@ const cc65_lineinfo* cc65_line_bysymref (cc65_dbginfo handle, unsigned symbol_id * returns NULL if the symbol id is invalid, otherwise a list of line infos. */ +const cc65_lineinfo* cc65_line_byspan (cc65_dbginfo handle, unsigned span_id); +/* Return line information for a a span. The function returns NULL if the + * span 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 */ @@ -535,6 +540,11 @@ const cc65_scopeinfo* cc65_scope_byname (cc65_dbginfo handle, const char* name); * the given name was found, otherwise a non empty scope list. */ +const cc65_scopeinfo* cc65_scope_byspan (cc65_dbginfo handle, unsigned span_id); +/* Return scope information for a a span. The function returns NULL if the + * span id is invalid, otherwise a list of line scopes. + */ + const cc65_scopeinfo* cc65_childscopes_byid (cc65_dbginfo handle, unsigned id); /* Return the direct child scopes of a scope with a given id. The function * returns NULL if no scope with this id was found, otherwise a list of the