1
0
mirror of https://github.com/cc65/cc65.git synced 2024-12-27 00:29:31 +00:00

Added cc65_get_scopelist. Added a few statistics field to the DbgInfo

structure.
          


git-svn-id: svn://svn.cc65.org/cc65/trunk@5189 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
uz 2011-08-17 15:18:22 +00:00
parent 771695577d
commit fa6b2e40fd
2 changed files with 65 additions and 24 deletions

View File

@ -196,6 +196,12 @@ struct DbgInfo {
/* Other stuff */ /* Other stuff */
SpanInfoList SpanInfoByAddr; /* Span infos sorted by unique address */ SpanInfoList SpanInfoByAddr; /* Span infos sorted by unique address */
/* Info data */
unsigned long MemUsage; /* Memory usage for the data */
unsigned MajorVersion; /* Major version number of loaded file */
unsigned MinorVersion; /* Minor version number of loaded file */
char FileName[1]; /* Name of input file */
}; };
/* Data used when parsing the debug info file */ /* Data used when parsing the debug info file */
@ -213,8 +219,6 @@ struct InputData {
unsigned long IVal; /* Integer constant */ unsigned long IVal; /* Integer constant */
StrBuf SVal; /* String constant */ StrBuf SVal; /* String constant */
cc65_errorfunc Error; /* Function called in case of errors */ cc65_errorfunc Error; /* Function called in case of errors */
unsigned MajorVersion; /* Major version number */
unsigned MinorVersion; /* Minor version number */
DbgInfo* Info; /* Pointer to debug info */ DbgInfo* Info; /* Pointer to debug info */
}; };
@ -1802,11 +1806,14 @@ static void DoneSpanInfoList (SpanInfoList* L)
static DbgInfo* NewDbgInfo (void) static DbgInfo* NewDbgInfo (const char* FileName)
/* Create a new DbgInfo struct and return it */ /* Create a new DbgInfo struct and return it */
{ {
/* Get the length of the name */
unsigned Len = strlen (FileName);
/* Allocate memory */ /* Allocate memory */
DbgInfo* Info = xmalloc (sizeof (DbgInfo)); DbgInfo* Info = xmalloc (sizeof (DbgInfo) + Len);
/* Initialize it */ /* Initialize it */
CollInit (&Info->FileInfoById); CollInit (&Info->FileInfoById);
@ -1826,6 +1833,11 @@ static DbgInfo* NewDbgInfo (void)
InitSpanInfoList (&Info->SpanInfoByAddr); InitSpanInfoList (&Info->SpanInfoByAddr);
Info->MemUsage = 0;
Info->MajorVersion = 0;
Info->MinorVersion = 0;
memcpy (&Info->FileName, FileName, Len+1);
/* Return it */ /* Return it */
return Info; return Info;
} }
@ -3675,7 +3687,7 @@ static void ParseVersion (InputData* D)
if (!IntConstFollows (D)) { if (!IntConstFollows (D)) {
goto ErrorExit; goto ErrorExit;
} }
D->MajorVersion = D->IVal; D->Info->MajorVersion = D->IVal;
NextToken (D); NextToken (D);
InfoBits |= ibMajor; InfoBits |= ibMajor;
break; break;
@ -3688,7 +3700,7 @@ static void ParseVersion (InputData* D)
if (!IntConstFollows (D)) { if (!IntConstFollows (D)) {
goto ErrorExit; goto ErrorExit;
} }
D->MinorVersion = D->IVal; D->Info->MinorVersion = D->IVal;
NextToken (D); NextToken (D);
InfoBits |= ibMinor; InfoBits |= ibMinor;
break; break;
@ -4403,25 +4415,23 @@ cc65_dbginfo cc65_read_dbginfo (const char* FileName, cc65_errorfunc ErrFunc)
0, /* Integer constant */ 0, /* Integer constant */
STRBUF_INITIALIZER, /* String constant */ STRBUF_INITIALIZER, /* String constant */
0, /* Function called in case of errors */ 0, /* Function called in case of errors */
0, /* Major version number */
0, /* Minor version number */
0, /* Pointer to debug info */ 0, /* Pointer to debug info */
}; };
D.FileName = FileName; D.FileName = FileName;
D.Error = ErrFunc; D.Error = ErrFunc;
/* Open the input file */ /* Open the input file */
D.F = fopen (D.FileName, "rt"); D.F = fopen (FileName, "rt");
if (D.F == 0) { if (D.F == 0) {
/* Cannot open */ /* Cannot open */
ParseError (&D, CC65_ERROR, ParseError (&D, CC65_ERROR,
"Cannot open input file \"%s\": %s", "Cannot open input file \"%s\": %s",
D.FileName, strerror (errno)); FileName, strerror (errno));
return 0; return 0;
} }
/* Create a new debug info struct */ /* Create a new debug info struct */
D.Info = NewDbgInfo (); D.Info = NewDbgInfo (FileName);
/* Prime the pump */ /* Prime the pump */
NextToken (&D); NextToken (&D);
@ -4438,30 +4448,34 @@ cc65_dbginfo cc65_read_dbginfo (const char* FileName, cc65_errorfunc ErrFunc)
ParseVersion (&D); ParseVersion (&D);
/* Do several checks on the version number */ /* Do several checks on the version number */
if (D.MajorVersion < VER_MAJOR) { if (D.Info->MajorVersion < VER_MAJOR) {
ParseError ( ParseError (
&D, CC65_ERROR, &D, CC65_ERROR,
"This is an old version of the debug info format that is no " "This is an old version of the debug info format that is no "
"longer supported. Version found = %u.%u, version supported " "longer supported. Version found = %u.%u, version supported "
"= %u.%u", "= %u.%u",
D.MajorVersion, D.MinorVersion, VER_MAJOR, VER_MINOR D.Info->MajorVersion, D.Info->MinorVersion,
VER_MAJOR, VER_MINOR
); );
goto CloseAndExit; goto CloseAndExit;
} else if (D.MajorVersion == VER_MAJOR && D.MinorVersion > VER_MINOR) { } else if (D.Info->MajorVersion == VER_MAJOR &&
D.Info->MinorVersion > VER_MINOR) {
ParseError ( ParseError (
&D, CC65_ERROR, &D, CC65_ERROR,
"This is a slightly newer version of the debug info format. " "This is a slightly newer version of the debug info format. "
"It might work, but you may get errors about unknown keywords " "It might work, but you may get errors about unknown keywords "
"and similar. Version found = %u.%u, version supported = %u.%u", "and similar. Version found = %u.%u, version supported = %u.%u",
D.MajorVersion, D.MinorVersion, VER_MAJOR, VER_MINOR D.Info->MajorVersion, D.Info->MinorVersion,
VER_MAJOR, VER_MINOR
); );
} else if (D.MajorVersion > VER_MAJOR) { } else if (D.Info->MajorVersion > VER_MAJOR) {
ParseError ( ParseError (
&D, CC65_WARNING, &D, CC65_WARNING,
"The format of this debug info file is newer than what we " "The format of this debug info file is newer than what we "
"know. Will proceed but probably fail. Version found = %u.%u, " "know. Will proceed but probably fail. Version found = %u.%u, "
"version supported = %u.%u", "version supported = %u.%u",
D.MajorVersion, D.MinorVersion, VER_MAJOR, VER_MINOR D.Info->MajorVersion, D.Info->MinorVersion,
VER_MAJOR, VER_MINOR
); );
} }
ConsumeEOL (&D); ConsumeEOL (&D);
@ -5127,7 +5141,6 @@ const cc65_segmentinfo* cc65_get_segmentlist (cc65_dbginfo Handle)
/* Return a list of all segments referenced in the debug information */ /* Return a list of all segments referenced in the debug information */
{ {
DbgInfo* Info; DbgInfo* Info;
const Collection* SegInfoByName;
cc65_segmentinfo* D; cc65_segmentinfo* D;
unsigned I; unsigned I;
@ -5137,16 +5150,13 @@ const cc65_segmentinfo* cc65_get_segmentlist (cc65_dbginfo Handle)
/* The handle is actually a pointer to a debug info struct */ /* The handle is actually a pointer to a debug info struct */
Info = (DbgInfo*) Handle; Info = (DbgInfo*) Handle;
/* Get a pointer to the segment list */
SegInfoByName = &Info->SegInfoByName;
/* Allocate memory for the data structure returned to the caller */ /* Allocate memory for the data structure returned to the caller */
D = new_cc65_segmentinfo (CollCount (SegInfoByName)); D = new_cc65_segmentinfo (CollCount (&Info->SegInfoById));
/* Fill in the data */ /* Fill in the data */
for (I = 0; I < CollCount (SegInfoByName); ++I) { for (I = 0; I < CollCount (&Info->SegInfoById); ++I) {
/* Copy the data */ /* Copy the data */
CopySegInfo (D->data + I, CollConstAt (SegInfoByName, I)); CopySegInfo (D->data + I, CollConstAt (&Info->SegInfoById, I));
} }
/* Return the result */ /* Return the result */
@ -5385,6 +5395,34 @@ void cc65_free_symbolinfo (cc65_dbginfo Handle, const cc65_symbolinfo* Info)
const cc65_scopeinfo* cc65_get_scopelist (cc65_dbginfo Handle)
/* Return a list of all scopes in the debug information */
{
DbgInfo* Info;
cc65_scopeinfo* D;
unsigned I;
/* Check the parameter */
assert (Handle != 0);
/* The handle is actually a pointer to a debug info struct */
Info = (DbgInfo*) Handle;
/* Allocate memory for the data structure returned to the caller */
D = new_cc65_scopeinfo (CollCount (&Info->ScopeInfoById));
/* Fill in the data */
for (I = 0; I < CollCount (&Info->ScopeInfoById); ++I) {
/* Copy the data */
CopyScopeInfo (D->data + I, CollConstAt (&Info->ScopeInfoById, I));
}
/* Return the result */
return D;
}
const cc65_scopeinfo* cc65_scope_byid (cc65_dbginfo Handle, unsigned Id) const cc65_scopeinfo* cc65_scope_byid (cc65_dbginfo Handle, unsigned Id)
/* Return the scope with a given id. The function returns NULL if no scope /* Return the scope with a given id. The function returns NULL if no scope
* with this id was found. * with this id was found.

View File

@ -471,6 +471,9 @@ struct cc65_scopeinfo {
const cc65_scopeinfo* cc65_get_scopelist (cc65_dbginfo handle);
/* Return a list of all scopes in the debug information */
const cc65_scopeinfo* cc65_scope_byid (cc65_dbginfo handle, unsigned id); const cc65_scopeinfo* cc65_scope_byid (cc65_dbginfo handle, unsigned id);
/* Return the scope with a given id. The function returns NULL if no scope /* Return the scope with a given id. The function returns NULL if no scope
* with this id was found. * with this id was found.