1
0
mirror of https://github.com/cc65/cc65.git synced 2024-10-01 00:57:11 +00:00

Added processing of modules, libraries, etc. Many other changes for new debug

info format.


git-svn-id: svn://svn.cc65.org/cc65/trunk@5141 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
uz 2011-08-09 19:11:38 +00:00
parent 36c99befcc
commit 604f74c5c2
3 changed files with 742 additions and 668 deletions

File diff suppressed because it is too large Load Diff

View File

@ -58,14 +58,17 @@ typedef unsigned cc65_line; /* Used to store line numbers */
typedef unsigned cc65_addr; /* Used to store (65xx) addresses */
typedef unsigned cc65_size; /* Used to store (65xx) sizes */
/* Pointer to an opaque data structure containing information from the debug
* info file. Actually a handle to the data in the file.
*/
typedef void* cc65_dbginfo;
/* A value that is used to mark invalid ids */
#define CC65_INV_ID (~0U)
/*****************************************************************************/
/* Debug info files */
/*****************************************************************************/
/* Severity for cc65_parseerror */
typedef enum {
CC65_WARNING,
@ -85,6 +88,68 @@ struct cc65_parseerror {
/* Function that is called in case of parse errors */
typedef void (*cc65_errorfunc) (const struct cc65_parseerror*);
/* Pointer to an opaque data structure containing information from the debug
* info file. Actually a handle to the data in the file.
*/
typedef void* cc65_dbginfo;
cc65_dbginfo cc65_read_dbginfo (const char* filename, cc65_errorfunc errorfunc);
/* Parse the debug info file with the given name. On success, the function
* will return a pointer to an opaque cc65_dbginfo structure, that must be
* passed to the other functions in this module to retrieve information.
* errorfunc is called in case of warnings and errors. If the file cannot be
* read successfully, NULL is returned.
*/
void cc65_free_dbginfo (cc65_dbginfo Handle);
/* Free debug information read from a file */
/*****************************************************************************/
/* Libraries */
/*****************************************************************************/
/* Library information */
typedef struct cc65_librarydata cc65_librarydata;
struct cc65_librarydata {
unsigned library_id; /* The internal library id */
const char* library_name; /* Name of the library */
};
typedef struct cc65_libraryinfo cc65_libraryinfo;
struct cc65_libraryinfo {
unsigned count; /* Number of data sets that follow */
cc65_librarydata data[1]; /* Data sets, number is dynamic */
};
cc65_libraryinfo* cc65_get_librarylist (cc65_dbginfo handle);
/* Return a list of all libraries */
cc65_libraryinfo* cc65_libraryinfo_byid (cc65_dbginfo handle, unsigned id);
/* Return information about a library with a specific id. The function
* returns NULL if the id is invalid (no such library) and otherwise a
* cc65_libraryinfo structure with one entry that contains the requested
* library information.
*/
void cc65_free_libraryinfo (cc65_dbginfo handle, cc65_libraryinfo* info);
/* Free a library info record */
/*****************************************************************************/
/* Line info */
/*****************************************************************************/
/* Type of line */
typedef enum {
CC65_LINE_ASM, /* Assembler source */
@ -120,119 +185,6 @@ struct cc65_lineinfo {
cc65_linedata data[1]; /* Data sets, number is dynamic */
};
/* Source file information */
typedef struct cc65_sourcedata cc65_sourcedata;
struct cc65_sourcedata {
unsigned source_id; /* The internal file id */
const char* source_name; /* Name of the file */
unsigned long source_size; /* Size of file */
unsigned long source_mtime; /* Modification time */
};
typedef struct cc65_sourceinfo cc65_sourceinfo;
struct cc65_sourceinfo {
unsigned count; /* Number of data sets that follow */
cc65_sourcedata data[1]; /* Data sets, number is dynamic */
};
/* Segment information.
* Notes:
* - output_name may be NULL if the data wasn't written to the output file
* (example: bss segment)
* - output_offs is invalid if there is no output_name, and may not be of
* much use in case of a relocatable output file
*/
typedef struct cc65_segmentdata cc65_segmentdata;
struct cc65_segmentdata {
unsigned segment_id; /* The internal segment id */
const char* segment_name; /* Name of the segment */
cc65_addr segment_start; /* Start address of segment */
cc65_addr segment_size; /* Size of segment */
const char* output_name; /* Output file this seg was written to */
unsigned long output_offs; /* Offset of this seg in output file */
};
typedef struct cc65_segmentinfo cc65_segmentinfo;
struct cc65_segmentinfo {
unsigned count; /* Number of data sets that follow */
cc65_segmentdata data[1]; /* Data sets, number is dynamic */
};
/* Symbol information */
typedef enum {
CC65_SYM_EQUATE,
CC65_SYM_LABEL, /* Some sort of address */
} cc65_symbol_type;
typedef struct cc65_symboldata cc65_symboldata;
struct cc65_symboldata {
unsigned symbol_id; /* Id of symbol */
const char* symbol_name; /* Name of symbol */
cc65_symbol_type symbol_type; /* Type of symbol */
cc65_size symbol_size; /* Size of symbol, 0 if unknown */
long symbol_value; /* Value of symbol */
unsigned symbol_segment; /* If the symbol is segment relative,
* this contains the id of segment,
* otherwise CC65_INV_ID
*/
unsigned scope_id; /* The scope this symbol is in */
};
typedef struct cc65_symbolinfo cc65_symbolinfo;
struct cc65_symbolinfo {
unsigned count; /* Number of data sets that follow */
cc65_symboldata data[1]; /* Data sets, number is dynamic */
};
/* Scope information */
typedef enum {
CC65_SCOPE_GLOBAL, /* Global scope */
CC65_SCOPE_MODULE, /* Module scope */
CC65_SCOPE_SCOPE, /* .PROC/.SCOPE */
CC65_SCOPE_STRUCT, /* .STRUCT */
CC65_SCOPE_ENUM, /* .ENUM */
} cc65_scope_type;
typedef struct cc65_scopedata cc65_scopedata;
struct cc65_scopedata {
unsigned scope_id; /* Id of scope */
const char* scope_name; /* Name of scope */
cc65_scope_type scope_type; /* Type of scope */
cc65_size scope_size; /* Size of scope, 0 if unknown */
unsigned scope_parent; /* Id of parent scope */
};
typedef struct cc65_scopeinfo cc65_scopeinfo;
struct cc65_scopeinfo {
unsigned count; /* Number of data sets that follow */
cc65_scopedata data[1]; /* Data sets, number is dynamic */
};
/*****************************************************************************/
/* Debug info files */
/*****************************************************************************/
cc65_dbginfo cc65_read_dbginfo (const char* filename, cc65_errorfunc errorfunc);
/* Parse the debug info file with the given name. On success, the function
* will return a pointer to an opaque cc65_dbginfo structure, that must be
* passed to the other functions in this module to retrieve information.
* errorfunc is called in case of warnings and errors. If the file cannot be
* read successfully, NULL is returned.
*/
void cc65_free_dbginfo (cc65_dbginfo Handle);
/* Free debug information read from a file */
/*****************************************************************************/
/* Line info */
/*****************************************************************************/
cc65_lineinfo* cc65_lineinfo_byaddr (cc65_dbginfo handle, unsigned long addr);
@ -251,12 +203,67 @@ void cc65_free_lineinfo (cc65_dbginfo handle, cc65_lineinfo* info);
/*****************************************************************************/
/* Modules */
/*****************************************************************************/
/* Module information */
typedef struct cc65_moduledata cc65_moduledata;
struct cc65_moduledata {
unsigned module_id; /* The internal module id */
const char* module_name; /* Name of the module */
unsigned source_id; /* Id of the module main file */
unsigned library_id; /* Id of the library if any */
};
typedef struct cc65_moduleinfo cc65_moduleinfo;
struct cc65_moduleinfo {
unsigned count; /* Number of data sets that follow */
cc65_moduledata data[1]; /* Data sets, number is dynamic */
};
cc65_moduleinfo* cc65_get_modulelist (cc65_dbginfo handle);
/* Return a list of all modules */
cc65_moduleinfo* cc65_moduleinfo_byid (cc65_dbginfo handle, unsigned id);
/* Return information about a module with a specific id. The function
* returns NULL if the id is invalid (no such module) and otherwise a
* cc65_moduleinfo structure with one entry that contains the requested
* module information.
*/
void cc65_free_moduleinfo (cc65_dbginfo handle, cc65_moduleinfo* info);
/* Free a module info record */
/*****************************************************************************/
/* Source files */
/*****************************************************************************/
/* Source file information */
typedef struct cc65_sourcedata cc65_sourcedata;
struct cc65_sourcedata {
unsigned source_id; /* The internal file id */
const char* source_name; /* Name of the file */
unsigned long source_size; /* Size of file */
unsigned long source_mtime; /* Modification time */
};
typedef struct cc65_sourceinfo cc65_sourceinfo;
struct cc65_sourceinfo {
unsigned count; /* Number of data sets that follow */
cc65_sourcedata data[1]; /* Data sets, number is dynamic */
};
cc65_sourceinfo* cc65_get_sourcelist (cc65_dbginfo handle);
/* Return a list of all source files */
@ -278,6 +285,31 @@ void cc65_free_sourceinfo (cc65_dbginfo handle, cc65_sourceinfo* info);
/* Segment information.
* Notes:
* - output_name may be NULL if the data wasn't written to the output file
* (example: bss segment)
* - output_offs is invalid if there is no output_name, and may not be of
* much use in case of a relocatable output file
*/
typedef struct cc65_segmentdata cc65_segmentdata;
struct cc65_segmentdata {
unsigned segment_id; /* The internal segment id */
const char* segment_name; /* Name of the segment */
cc65_addr segment_start; /* Start address of segment */
cc65_addr segment_size; /* Size of segment */
const char* output_name; /* Output file this seg was written to */
unsigned long output_offs; /* Offset of this seg in output file */
};
typedef struct cc65_segmentinfo cc65_segmentinfo;
struct cc65_segmentinfo {
unsigned count; /* Number of data sets that follow */
cc65_segmentdata data[1]; /* Data sets, number is dynamic */
};
cc65_segmentinfo* cc65_get_segmentlist (cc65_dbginfo handle);
/* Return a list of all segments referenced in the debug information */
@ -298,6 +330,35 @@ void cc65_free_segmentinfo (cc65_dbginfo handle, cc65_segmentinfo* info);
/* Symbol information */
typedef enum {
CC65_SYM_EQUATE,
CC65_SYM_LABEL, /* Some sort of address */
} cc65_symbol_type;
typedef struct cc65_symboldata cc65_symboldata;
struct cc65_symboldata {
unsigned symbol_id; /* Id of symbol */
const char* symbol_name; /* Name of symbol */
cc65_symbol_type symbol_type; /* Type of symbol */
cc65_size symbol_size; /* Size of symbol, 0 if unknown */
long symbol_value; /* Value of symbol */
unsigned segment_id; /* If the symbol is segment relative,
* this contains the id of segment,
* otherwise CC65_INV_ID
*/
unsigned scope_id; /* The scope this symbol is in */
unsigned parent_id; /* Parent symbol for cheap locals */
};
typedef struct cc65_symbolinfo cc65_symbolinfo;
struct cc65_symbolinfo {
unsigned count; /* Number of data sets that follow */
cc65_symboldata data[1]; /* Data sets, number is dynamic */
};
cc65_symbolinfo* cc65_symbol_byid (cc65_dbginfo handle, unsigned id);
/* Return the symbol with a given id. The function returns NULL if no symbol
* with this id was found.
@ -326,6 +387,34 @@ void cc65_free_symbolinfo (cc65_dbginfo Handle, cc65_symbolinfo* Info);
/* Scope information */
typedef enum {
CC65_SCOPE_GLOBAL, /* Global scope */
CC65_SCOPE_MODULE, /* Module scope */
CC65_SCOPE_SCOPE, /* .PROC/.SCOPE */
CC65_SCOPE_STRUCT, /* .STRUCT */
CC65_SCOPE_ENUM, /* .ENUM */
} cc65_scope_type;
typedef struct cc65_scopedata cc65_scopedata;
struct cc65_scopedata {
unsigned scope_id; /* Id of scope */
const char* scope_name; /* Name of scope */
cc65_scope_type scope_type; /* Type of scope */
cc65_size scope_size; /* Size of scope, 0 if unknown */
unsigned scope_parent; /* Id of parent scope */
unsigned symbol_id; /* Id of scope symbol if any */
unsigned module_id; /* Id of the module */
};
typedef struct cc65_scopeinfo cc65_scopeinfo;
struct cc65_scopeinfo {
unsigned count; /* Number of data sets that follow */
cc65_scopedata data[1]; /* Data sets, number is dynamic */
};
cc65_scopeinfo* cc65_scope_byid (cc65_dbginfo handle, unsigned id);
/* Return the scope with a given id. The function returns NULL if no scope
* with this id was found.

View File

@ -118,8 +118,8 @@ static void PrintSymbolData (const cc65_symboldata* D)
/* Print the data for one symbol */
{
char Segment[256] = { 0 }; /* Needs dynamic alloc ### */
if (D->symbol_segment != CC65_INV_ID) {
cc65_segmentinfo* I = cc65_segmentinfo_byid (Info, D->symbol_segment);
if (D->segment_id != CC65_INV_ID) {
cc65_segmentinfo* I = cc65_segmentinfo_byid (Info, D->segment_id);
if (I && I->count == 1) {
sprintf (Segment, "segment=%s,", I->data[0].segment_name);
cc65_free_segmentinfo (Info, I);