Commit 4db4d980 authored by Ben Laughton's avatar Ben Laughton
Browse files

Initial import of DDTLib library into CVS.

Detail:                         
  This is Julian Smith's library to extract debug information from executables,
  required by his Trace library.                      
  The build system for the main library has been restructured not to use
  Makatic.
  There may be binary-only copies of this library floating around under the
  name 'DDT', but I've taken the liberty of renaming the library DDTLib to
  avoid possible confusion with the DDT module.
                                
Admin:                          
  all, clean, and export phases tested.
  Tested using the ATM driver, which uses DebugLib, which uses Trace, which
  uses DDTLib; appears to work as previous binary-only version did.
Dir <Obey$Dir>
WimpSlot 2048k
amu THROWBACK=-throwback all
Dir <Obey$Dir>
WimpSlot 2048k
amu_machine clean
Dir <Obey$Dir>
WimpSlot 2048k
amu THROWBACK=-throwback debug
Dir <Obey$Dir>
amu PHASE=hdrs export
amu PHASE=libs export
s/** gitlab-language=armasm linguist-language=armasm linguist-detectable=true
c/** gitlab-language=c linguist-language=c linguist-detectable=true
h/** gitlab-language=c linguist-language=c linguist-detectable=true
**/h/** gitlab-language=c linguist-language=c linguist-detectable=true
This diff is collapsed.
GNU LESSER GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
This version of the GNU Lesser General Public License incorporates
the terms and conditions of version 3 of the GNU General Public
License, supplemented by the additional permissions listed below.
0. Additional Definitions.
As used herein, "this License" refers to version 3 of the GNU Lesser
General Public License, and the "GNU GPL" refers to version 3 of the GNU
General Public License.
"The Library" refers to a covered work governed by this License,
other than an Application or a Combined Work as defined below.
An "Application" is any work that makes use of an interface provided
by the Library, but which is not otherwise based on the Library.
Defining a subclass of a class defined by the Library is deemed a mode
of using an interface provided by the Library.
A "Combined Work" is a work produced by combining or linking an
Application with the Library. The particular version of the Library
with which the Combined Work was made is also called the "Linked
Version".
The "Minimal Corresponding Source" for a Combined Work means the
Corresponding Source for the Combined Work, excluding any source code
for portions of the Combined Work that, considered in isolation, are
based on the Application, and not on the Linked Version.
The "Corresponding Application Code" for a Combined Work means the
object code and/or source code for the Application, including any data
and utility programs needed for reproducing the Combined Work from the
Application, but excluding the System Libraries of the Combined Work.
1. Exception to Section 3 of the GNU GPL.
You may convey a covered work under sections 3 and 4 of this License
without being bound by section 3 of the GNU GPL.
2. Conveying Modified Versions.
If you modify a copy of the Library, and, in your modifications, a
facility refers to a function or data to be supplied by an Application
that uses the facility (other than as an argument passed when the
facility is invoked), then you may convey a copy of the modified
version:
a) under this License, provided that you make a good faith effort to
ensure that, in the event an Application does not supply the
function or data, the facility still operates, and performs
whatever part of its purpose remains meaningful, or
b) under the GNU GPL, with none of the additional permissions of
this License applicable to that copy.
3. Object Code Incorporating Material from Library Header Files.
The object code form of an Application may incorporate material from
a header file that is part of the Library. You may convey such object
code under terms of your choice, provided that, if the incorporated
material is not limited to numerical parameters, data structure
layouts and accessors, or small macros, inline functions and templates
(ten or fewer lines in length), you do both of the following:
a) Give prominent notice with each copy of the object code that the
Library is used in it and that the Library and its use are
covered by this License.
b) Accompany the object code with a copy of the GNU GPL and this license
document.
4. Combined Works.
You may convey a Combined Work under terms of your choice that,
taken together, effectively do not restrict modification of the
portions of the Library contained in the Combined Work and reverse
engineering for debugging such modifications, if you also do each of
the following:
a) Give prominent notice with each copy of the Combined Work that
the Library is used in it and that the Library and its use are
covered by this License.
b) Accompany the Combined Work with a copy of the GNU GPL and this license
document.
c) For a Combined Work that displays copyright notices during
execution, include the copyright notice for the Library among
these notices, as well as a reference directing the user to the
copies of the GNU GPL and this license document.
d) Do one of the following:
0) Convey the Minimal Corresponding Source under the terms of this
License, and the Corresponding Application Code in a form
suitable for, and under terms that permit, the user to
recombine or relink the Application with a modified version of
the Linked Version to produce a modified Combined Work, in the
manner specified by section 6 of the GNU GPL for conveying
Corresponding Source.
1) Use a suitable shared library mechanism for linking with the
Library. A suitable mechanism is one that (a) uses at run time
a copy of the Library already present on the user's computer
system, and (b) will operate properly with a modified version
of the Library that is interface-compatible with the Linked
Version.
e) Provide Installation Information, but only if you would otherwise
be required to provide such information under section 6 of the
GNU GPL, and only to the extent that such information is
necessary to install and execute a modified version of the
Combined Work produced by recombining or relinking the
Application with a modified version of the Linked Version. (If
you use option 4d0, the Installation Information must accompany
the Minimal Corresponding Source and Corresponding Application
Code. If you use option 4d1, you must provide the Installation
Information in the manner specified by section 6 of the GNU GPL
for conveying Corresponding Source.)
5. Combined Libraries.
You may place library facilities that are a work based on the
Library side by side in a single library together with other library
facilities that are not Applications and are not covered by this
License, and convey such a combined library under terms of your
choice, if you do both of the following:
a) Accompany the combined library with a copy of the same work based
on the Library, uncombined with any other library facilities,
conveyed under the terms of this License.
b) Give prominent notice with the combined library that part of it
is a work based on the Library, and explaining where to find the
accompanying uncombined form of the same work.
6. Revised Versions of the GNU Lesser General Public License.
The Free Software Foundation may publish revised and/or new versions
of the GNU Lesser General Public License from time to time. Such new
versions will be similar in spirit to the present version, but may
differ in detail to address new problems or concerns.
Each version is given a distinguishing version number. If the
Library as you received it specifies that a certain numbered version
of the GNU Lesser General Public License "or any later version"
applies to it, you have the option of following the terms and
conditions either of that published version or of any later version
published by the Free Software Foundation. If the Library as you
received it does not specify a version number of the GNU Lesser
General Public License, you may choose any version of the GNU Lesser
General Public License ever published by the Free Software Foundation.
If the Library as you received it specifies that a proxy can decide
whether future versions of the GNU Lesser General Public License shall
apply, that proxy's public statement of acceptance of any version is
permanent authorization for you to choose that version for the
Library.
File added
Tue 07 Apr 1998
Fixed bug - fileinfo consitst of a series of file entry items, not just
one as previously assumed. C++ often results in more than one, leaving
MeMCheck unable to give C++ source info.
As a result, DDT_CopySectionFilename now gets the module name (in the
section item), rather then the filename of the first fileentry.
Added DDT_Throwback()
/*
* Copyright Julian Smith.
*
* This file is part of DDT.
*
* DDT is free software: you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your
* option) any later version.
*
* DDT is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
* Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with DDT. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __AIFHeader_h
#define __AIFHeader_h
extern char* DDT_AIFHeader_ro_base;
extern char* DDT_AIFHeader_rw_base;
extern char* DDT_AIFHeader_zi_base;
extern char* DDT_AIFHeader_rw_limit;
extern char* DDT_AIFHeader_ro_limit;
extern char* DDT_AIFHeader_zi_limit;
typedef struct {
int BL_decompress_code;
int BL_selfreloc_code;
int BL_zeroinit_code;
int BL_imageentrypoint;
int swi_OS_Exit;
int size_ro;
int size_rw;
int size_debug;
int size_zeroinit;
int debug_type;
int image_base;
int workspace;
int reserved[ 4];
int zeroinitcode[ 16];
}
DDT_AIFHeader_block;
#endif
/*
* Copyright Julian Smith.
*
* This file is part of DDT.
*
* DDT is free software: you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your
* option) any later version.
*
* DDT is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
* Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with DDT. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __DDT_DDT_h
#define __DDT_DDT_h
typedef struct {
void* instruction;
char filename[ 256];
int linenumber;
int column;
}
DDT_instruction_info;
typedef void* DDT_ddtinfo_handle;
void DDT_FindDDTInfoForInstruction( DDT_ddtinfo_handle handle, DDT_instruction_info* block, void* ptr);
/*
Fills in 'block' for the instruction at address 'ptr'.
*/
void DDT_DDTInfo( DDT_instruction_info* block, void* ptr);
/*
Calls DDT_FindDDTInfoForInstruction with most recent DDT_ddtinfo_handle
found in DDT_LoadDDTInfoForFile().
DDT_FindDDTInfoForInstruction is nicer.
*/
DDT_ddtinfo_handle DDT_LoadDDTInfo( void);
/*
This should be done early in main(), because the filename to be loaded
is found from _kernel_command_string(), which may contain a system
variable which could change, such as <Obey$Dir>.
Returns 0 if couldn't load info.
*/
DDT_ddtinfo_handle DDT_GetDDTInfo( const void* ddtinfo, int len);
/*
Expects 'len' bytes of DDT info to be at address 'ddtinfo'.
*/
DDT_ddtinfo_handle DDT_LoadDDTInfoForFile( const char* filename);
/*
Attempts to load debugging information from the specified file. This
should be done early in main(), because the filename to be loaded is
found from _kernel_command_string(), which may contain a system variable
which could change, such as <Obey$Dir>.
Returns 0 if error, otherwise opaque handle to be passed to
DDT_FindDDTInfoForAddress.
*/
#endif
/*
* Copyright Julian Smith.
*
* This file is part of DDT.
*
* DDT is free software: you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your
* option) any later version.
*
* DDT is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
* Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with DDT. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __DDT_DDT2_h
#define __DDT_DDT2_h
#ifndef __Desk_Core_h
#include "Desk.Core.h"
#endif
#ifndef __AIFHeader_h
#include "AIFHeader.h"
#endif
#ifndef __DDT_DDT_h
#include "DDT.h"
#endif
typedef enum {
DDT_itemtype_SECTION = 1,
DDT_itemtype_PROC = 2,
DDT_itemtype_PROC_END = 3,
DDT_itemtype_VARIABLE = 4,
DDT_itemtype_TYPE = 5,
DDT_itemtype_STRUCT = 6,
DDT_itemtype_ARRAY = 7,
DDT_itemtype_SUBRANGE = 8,
DDT_itemtype_SET = 9,
DDT_itemtype_FILEINFO = 10,
DDT_itemtype_ENUM_CONTINUOUS = 11,
DDT_itemtype_ENUM_DISCONTINUOUS = 12,
DDT_itemtype_PROC_DECLARATION = 13,
DDT_itemtype_NAMESCOPE_BEGIN = 14,
DDT_itemtype_NAMESCOPE_END = 15
}
DDT_itemtype;
typedef struct {
unsigned int itemkind : 16; /*1 section, 2 procedure, 3 endproc, etc. */
unsigned int itemlength : 16;
}
DDT_itemheader;
typedef struct {
struct {
unsigned int stridx : 24;
unsigned int global : 1;
unsigned int symboltype : 7; /* 0 absolute, 1 code, 2 data, 3 zero init. */
}
flags;
int value;
}
DDT_symbol;
typedef struct {
char length;
char first3[3];
}
DDT_string;
typedef struct {
DDT_itemheader header;
union {
int value;
struct {
unsigned int language : 8;
unsigned int debuglines : 1;
unsigned int debugvars : 1;
unsigned int spare : 14;
unsigned int debugversion : 8;
}
data;
}
flags;
char* codeaddr;
char* dataaddr;
int codesize;
int datasize;
int fileinfo; /* Offset in debugging data *relative to this section* */
int debugsize; /* Total size of all debug info for this section */
union {
int nsyms;
DDT_string name;
}
name_or_nsyms;
}
DDT_section;
typedef struct {
unsigned int linenumber : 22;
unsigned int linepos : 10;
}
DDT_sourcepos;
typedef struct {
DDT_itemheader header;
int type; /* Return type. */
int args;
DDT_sourcepos sourcepos;
void* startaddr;
void* bodyaddr; /* First instruction after procedure entry sequence. */
int endproc;
int fileentry;
DDT_string name;
}
DDT_procedure;
typedef struct {
DDT_itemheader header;
DDT_sourcepos sourcepos;
void* endaddr;
int fileentry;
int nreturns;
void* retaddrs[1];
}
DDT_endproc;
typedef struct {
int fragmentsize;
int firstline;
int lastline;
char* codeaddr;
int codesize;
}
DDT_fragment;
/* Followed by some DDT_lineinfo's. */
typedef struct {
int n; /* Num fragments. */
}
DDT_fileinfo_data;
/* Followed by n DDT_fragment's. */
/*
typedef struct {
DDT_itemheader header;
int length;
int date; |* Seconds since 1970. *|
DDT_string filename;
}
DDT_fileinfo;
*/
/* Followed by a DDT_fileinfo_data;. */
/* Incorrect - use DDT_fileinfo2 instead */
typedef struct
{
int len; /* 0 means this the last one */
int date;
DDT_string filename;
/*
Followed by a DDT_fileinfo_data.
*/
}
DDT_fileentry;
typedef struct
{
DDT_itemheader header;
/* Followed by a number of DDT_fileentry's. */
}
DDT_fileinfo2;
typedef struct {
char* data;
int size;
Desk_bool loaded;
DDT_AIFHeader_block aifheader;
char* file_address; // Address in AIF file of start of debug data.
// Useful for diagnostics - print data-'file_address' to get
// data that can be compared with Zap's code addresses in original file.
}
DDT_debugareadata;
typedef struct {
void* instruction;
DDT_debugareadata* debugdata;
DDT_section* section;
DDT_procedure* proc;
char filename[ 256];
char procname[ 256];
char name[ 256]; /* module name */
DDT_sourcepos pos;
struct {
char* name; /* From low-level debug info */
DDT_symbol symbol;
}
symbol;
}
DDT_instruction_info2;
DDT_section* DDT_GetEnclosingSection( char* instruction, DDT_debugareadata* ddtdata);
DDT_procedure* DDT_GetEnclosingProcedure( char* instruction, DDT_section* section);
void DDT_GetSourcePos( DDT_instruction_info2* info2, char* instruction, DDT_section* section);
void DDT_CopySectionFilename( char* buffer, int buflen, DDT_section* section);
void DDT_CopyString( char* buffer, int buflen, DDT_string* string);
void DDT_FindDDTInfoForInstruction2( DDT_debugareadata* debugarea, DDT_instruction_info2* block, void* instruction);
/*
Fills in 'block' for address 'instruction'.
*/
void DDT_FindDDTInfoForInstruction3( DDT_ddtinfo_handle debugarea, DDT_instruction_info2* block, void* instruction);
/*
As DDT_FindDDTInfoForInstruction2, except that usees opaque handle.
*/
void DDT_FindNearestSymbol( DDT_instruction_info2* block);
typedef int (*DDT_printffn)( void* reference, const char* fmt, ...);
void DDT_PrintDDTInfo_1( DDT_printffn fn, void* reference, DDT_instruction_info2* ddtinfo);
void DDT_PrintDDTInfo_2( DDT_printffn fn, void* reference, DDT_instruction_info2* ddtinfo, const char* separator);
void DDT_Throwback( DDT_instruction_info2* ddtinfo, const char* rootfilename, const char* format, ...);
/*
Makes a throwback item for the specified source position. If the
filename isn't complete, it is prepended with 'rootfilename'.^.
The throwback text is specified by format, ... as in printf,
using an internal 1024-character buffer.
Currently there's no control over the details of the throwback
such as warning/error, severity etc.
Returns quietly if ddtinfo doesn't have source info, or
throwback SWIs fail.
*/
#endif
# File: Makefile
# Purpose: Makefile for DDTLib
# Author: Ben Laughton
#
# History:
#
# 2000-04-10: BAL
# Created.
# ------------------------------------------------------------------------------
# Paths
#
EXP_DIR = <Lib$Dir>.DDTLib
LIBDIR = <Lib$Dir>
# ------------------------------------------------------------------------------
# Generic options
#
MKDIR = mkdir -p
AS = objasm
CC = $(MemCheckCC) cc
C++ = c++
CMHG = cmhg
CP = copy
LD = link
RM = remove
WIPE = -wipe
CD = dir
CHMOD = access
TOUCH = create
DATA2AOF = datatoaof
MODSQZ = modsqz
LB = libfile
# ------------------------------------------------------------------------------
# Flags
#
AFLAGS = -depend !Depend $(THROWBACK) $(EXTRA_A_FLAGS) -stamp -quit
CCFLAGS = -depend !Depend $(THROWBACK) $(INCLUDES) $(DFLAGS) -c -Wsp -ffah
LDFLAGS = -aof
CPFLAGS = ~cfr~v
WFLAGS = ~c~vr
LBFLAGS = -c
CHMODFLAGS = RW/r
DFLAGS = $(EXTRA_C_FLAGS)
INCLUDES = -IC:,TCPIPLibs:
# ------------------------------------------------------------------------------
# Program specific options
#
COMPONENT = DDTLib
TARGET = l.DDTLib$(LIBSUFFIX)
EXPORTS = $(EXP_C_H).$(COMPONENT)
OBJS =\
$(EXT).AIFHeader\
$(EXT).DDT\
$(EXT).DDT2\
$(EXT).GetProc\
$(EXT).NrSymb\
$(EXT).Print1\
$(EXT).SectFile\
$(EXT).SrcPos\
$(EXT).ThrowBack
# ------------------------------------------------------------------------------
# Rule patterns
#
.SUFFIXES: .o .z .od .odz .i .h .s .c
.c.i:; $(CC) $(CCFLAGS) -C -E $< >> $@
.c.o:; $(CC) $(CCFLAGS) -o $@ $<
.c.od:; $(CC) $(CCFLAGS) -fn -g -o $@ $<
.c.z:; $(CC) $(CCFLAGS) -DDesk__MODULE_CLIENT -zM -o $@ $<
.c.odz:; $(CC) $(CCFLAGS) -DDesk__MODULE_CLIENT -zM -fn -g -o $@ $<
.s.i:; @echo $@
.s.o:; $(AS) $(AFLAGS) -pd "Desk_AS_EMBED_FNNAMES SETA 0" $< $@
.s.z:; $(AS) $(AFLAGS) -pd "Desk_AS_EMBED_FNNAMES SETA 0" $< $@
.s.od:; $(AS) $(AFLAGS) -pd "Desk_AS_EMBED_FNNAMES SETA 1" $< $@
.s.odz:; $(AS) $(AFLAGS) -pd "Desk_AS_EMBED_FNNAMES SETA 1" $< $@
# ------------------------------------------------------------------------------
# Local build rules
#
all: $(TARGET)
debug: $(TARGET)
preprocess: $(TARGET)
$(TARGET): $(OBJS) $(LIBS) $(EXT).local_dirs
$(MKDIR) l
$(LB) $(LBFLAGS) -o $@ $(OBJS)
# ------------------------------------------------------------------------------
# Common build rules
$(EXT).local_dirs:
@$(MKDIR) $(EXT)
@$(TOUCH) $@
$(EXP_DIR).dirs:
@$(MKDIR) $(EXP_DIR).h
@$(MKDIR) $(EXP_DIR).o
@$(TOUCH) $@
# ------------------------------------------------------------------------------
# RISC OS ROM build rules
#
export: export_$(PHASE)
export_hdrs: $(EXP_DIR).dirs
@$(CP) Export.h $(EXP_DIR).* $(CPFLAGS)
export_libs: $(TARGET) $(EXP_DIR).dirs
@$(CP) $(TARGET) $(EXP_DIR).o.* $(CPFLAGS)
clean:
$(WIPE) $(EXT) $(WFLAGS)
# ------------------------------------------------------------------------------
# Dynamic dependencies:
# File: Makefile
# Purpose: Makefile for DDTLib
# Author: Ben Laughton
#
# History:
#
# 2000-04-10: BAL
# Created.
# ------------------------------------------------------------------------------
# Generic options
#
MKDIR = cdir
CP = copy
RM = remove
WIPE = -wipe
STRIPDEPND = stripdepnd
# ------------------------------------------------------------------------------
# Flags
#
CPFLAGS = ~cfr~v
WFLAGS = ~c~vr
# ------------------------------------------------------------------------------
# Program specific options
#
COMPONENT = DDTLib
# C debugging and DebugLib do not map 1<->1 since DebugLib is used for other
# stuff as well.
C_DEBUG_ON = -DDesk_DEBUG
C_DEBUG_OFF = -DNDEBUG
# ------------------------------------------------------------------------------
# Build rules
#
# Local
all:
@amu -f MainMake $(MFLAGS) EXTRA_C_FLAGS=$(C_DEBUG_OFF) LIBSUFFIX= EXT=o
@amu -f MainMake $(MFLAGS) EXTRA_C_FLAGS=$(C_DEBUG_OFF) LIBSUFFIX=_M EXT=z
@echo $(COMPONENT): build complete
debug:
@amu -f MainMake $(MFLAGS) EXTRA_C_FLAGS=$(C_DEBUG_ON) LIBSUFFIX=_D EXT=od
@amu -f MainMake $(MFLAGS) EXTRA_C_FLAGS=$(C_DEBUG_ON) LIBSUFFIX=_M_D EXT=odz
@echo $(COMPONENT): debug build complete
preprocess:
@amu -f MainMake $(MFLAGS) EXTRA_C_FLAGS=$(C_DEBUG_OFF) EXT=i
@echo $(COMPONENT): preprocessing complete
export: export_$(PHASE)
export_hdrs:
@amu -f MainMake $(MFLAGS) TARGET=AvoidAMUBug EXT=AvoidAMUBug
@echo $(COMPONENT): export complete (hdrs)
export_libs:
@amu -f MainMake $(MFLAGS) EXTRA_C_FLAGS=$(C_DEBUG_OFF) LIBSUFFIX= EXT=o
@amu -f MainMake $(MFLAGS) EXTRA_C_FLAGS=$(C_DEBUG_OFF) LIBSUFFIX=_M EXT=z
@echo $(COMPONENT): export complete (libs)
clean:
@amu -f MainMake $(MFLAGS) EXT=o
@amu -f MainMake $(MFLAGS) EXT=z
@amu -f MainMake $(MFLAGS) EXT=od
@amu -f MainMake $(MFLAGS) EXT=odz
@amu -f MainMake $(MFLAGS) EXT=i
@$(WIPE) l $(WFLAGS)
@$(STRIPDEPND) MainMake
@echo $(COMPONENT): cleaned
# Dynamic dependencies:
/*
* Copyright Julian Smith.
*
* This file is part of DDT.
*
* DDT is free software: you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your
* option) any later version.
*
* DDT is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
* Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with DDT. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "kernel.h"
#include "Desk/Debug.h"
#include "Desk/Error.h"
#include "DDTLib/AIFHeader.h"
#include "DDTLib/DDT.h"
#include "DDTLib/DDT2.h"
#include "defs.h"
DDT_section* DDT_GetEnclosingSection( char* instruction, DDT_debugareadata* ddtdata)
{
DDT_section* section;
DDT_section* bestsection = NULL;
int bestsection_language = -1;
for (
section = (DDT_section*) ddtdata->data;
(char*) section - ddtdata->data < ddtdata->size;
section = (DDT_section*) (((char*) section) + section->debugsize)
)
{
Desk_Debug4_Printf( Desk_error_PLACE "Section at 0x%p [0x%p]\n", section, FILEADDRESS( section));
while ( section->header.itemkind != 1)
{ // Not a section
section = (DDT_section*) (((char*) section) + section->header.itemlength);
Desk_Debug3_Printf( Desk_error_PLACE "section = 0x%p [0x%p]\n", section, FILEADDRESS( section));
if ( (char*) section - ddtdata->data >= ddtdata->size) {
Desk_Debug_Printf( Desk_error_PLACE "Run beyond debug area while skipping non-sections\n");
break;
}
}
Desk_Debug4_Printf( Desk_error_PLACE "Section size %i\n", section->debugsize);
if ( section->flags.data.debugversion != 3 && section->flags.data.debugversion != 2)
{
Desk_Debug4_Printf( Desk_error_PLACE "ASD Version %i - skipping\n", section->flags.data.debugversion);
continue; // We only understand ASD 3
}
#ifdef Desk_DEBUG
if ( Desk_debug_level > 5)
{
char filename[ 256];
DDT_CopySectionFilename( filename, 256, section);
Desk_Debug_Printf( Desk_error_PLACE "Section %p - itemkind=%i, ASD %i, code 0x%p-0x%p (%i), filename='%s'\n",
section,
section->header.itemkind,
section->flags.data.debugversion,
section->codeaddr,
(char*) section->codeaddr + section->codesize,
section->codesize,
filename
);
}
#endif
Desk_Debug_Assert( section->header.itemkind == 1);
if ( instruction >= section->codeaddr && instruction < section->codeaddr+section->codesize)
{
#ifdef Desk_DEBUG
{
Desk_Debug_Printf( Desk_error_PLACE "An enclosing section is:\n");
Desk_Debug_Printf( Desk_error_PLACE " language = %i\n", section->flags.data.language);
Desk_Debug_Printf( Desk_error_PLACE " debuglines = %i\n", section->flags.data.debuglines);
Desk_Debug_Printf( Desk_error_PLACE " debugvars = %i\n", section->flags.data.debugvars);
Desk_Debug_Printf( Desk_error_PLACE " -unused- = %i\n", section->flags.data.spare);
Desk_Debug_Printf( Desk_error_PLACE " debugversion= %i\n", section->flags.data.debugversion);
Desk_Debug_Printf( Desk_error_PLACE "\n");
Desk_Debug_Printf( Desk_error_PLACE " codestart = 0x%p\n", section->codeaddr);
Desk_Debug_Printf( Desk_error_PLACE " datastart = 0x%p\n", section->dataaddr);
Desk_Debug_Printf( Desk_error_PLACE " codesize = %i\n", section->codesize);
Desk_Debug_Printf( Desk_error_PLACE " datasize = %i\n", section->datasize);
Desk_Debug_Printf( Desk_error_PLACE " fileinfo = %i\n", section->fileinfo);
Desk_Debug_Printf( Desk_error_PLACE " debugsize = %i\n", section->debugsize);
Desk_Debug_Printf( Desk_error_PLACE "\n");
if ( 0==section->flags.data.language)
{ // This section only contains low level info.
int i;
DDT_symbol* syms = (DDT_symbol*) (section+1);
Desk_Debug_Printf( Desk_error_PLACE " Low-level only. numsyms = %i\n", section->name_or_nsyms.nsyms);
for ( i=0; i<section->name_or_nsyms.nsyms; i++)
{
Desk_Debug5_Printf( Desk_error_PLACE "sym %i: stridx=%i, global=%i, symboltype=%i\n",
i, syms[i].flags.stridx, syms[i].flags.global, syms[i].flags.symboltype
);
}
Desk_Debug_Printf( Desk_error_PLACE "\n");
}
}
#endif
if ( section->flags.data.language > bestsection_language)
{
Desk_Debug_Printf( Desk_error_PLACE "Replacing old best section language %i, with language %i\n",
bestsection_language, section->flags.data.language
);
bestsection_language = section->flags.data.language;
bestsection = section;
}
//return section;
}
}
return bestsection;
}
DDT_ddtinfo_handle DDT_LoadDDTInfo( void)
{
char* cl = _kernel_command_string();
char filename[ 256] = "";
char* firstspace;
strncat( filename, cl, 255);
firstspace = strchr( filename, ' ');
if ( firstspace) *firstspace = 0;
Desk_Debug2_Printf( "Filename is '%s'\n", filename);
return DDT_LoadDDTInfoForFile( filename);
}
DDT_ddtinfo_handle DDT_global_lastddtinfohandle = 0;
DDT_ddtinfo_handle DDT_GetDDTInfo( const void* ddtinfo, int len)
{
DDT_debugareadata* ddtdata;
if ( !ddtinfo || len==0) return 0;
ddtdata = (DDT_debugareadata*) malloc( sizeof( DDT_debugareadata));
if ( !ddtdata)
{
Desk_Debug_Printf( Desk_error_PLACE "malloc failed\n");
return NULL;
}
ddtdata->loaded = Desk_bool_TRUE;
ddtdata->data = (char*) ddtinfo;
ddtdata->size = len;
Desk_Debug2_Printf( "DDT info is stored in memory 0x%p-0x%p (%i)\n",
ddtdata->data,
(char*) ddtdata->data + ddtdata->size,
ddtdata->size
);
DDT_global_lastddtinfohandle = (DDT_ddtinfo_handle) ddtdata;
return (DDT_ddtinfo_handle) ddtdata;
}
DDT_ddtinfo_handle DDT_LoadDDTInfoForFile( const char* filename)
{
/*
DDT_AIFHeader_block* aifheader = (DDT_AIFHeader_block*) 0x8000;
char* ddtinfo = ((char*) aifheader) + global_ddtdata.aifheader.size_ro + global_ddtdata.aifheader.size_rw;
*/
FILE* file;
int DDT_offset;
DDT_debugareadata* ddtdata = (DDT_debugareadata*) malloc( sizeof( DDT_debugareadata));
if ( !ddtdata)
{
Desk_Debug_Printf( Desk_error_PLACE "malloc failed\n");
return NULL;
}
ddtdata->loaded = Desk_bool_TRUE;
Desk_Debug2_Printf( "Filename is '%s'\n", filename);
file = fopen( filename, "rb");
if (!file)
{
/*fprintf( stderr, "Couldn't read image file '%s'\n", filename);*/
return NULL;
}
/* Load AIF header from !RunImage */
fread( &ddtdata->aifheader, 1, sizeof( DDT_AIFHeader_block), file);
if ( ddtdata->aifheader.size_debug == 0)
{
Desk_Debug2_Printf( "DDT_LoadDDTInfo - no debugging data in file\n");
return NULL;
}
DDT_offset = ddtdata->aifheader.size_ro + ddtdata->aifheader.size_rw;
ddtdata->file_address = (char*) DDT_offset + 0x8000;
//DDT_global_file_address = ddtdata->file_address; // For global use in diagnostics.
Desk_Debug2_Printf( "DDT_offset is %i\n", DDT_offset);
if ( 0 != fseek( file, (long int) DDT_offset, SEEK_SET))
{
/*fprintf( stderr, "Couldn't find debug info\n");*/
return NULL;
}
ddtdata->data = (char*) malloc( ddtdata->aifheader.size_debug);
if (!ddtdata->data)
{
/*fprintf( stderr, "Couldn't malloc space for debug info - %i bytes\n", global_ddtdata.aifheader.size_debug);*/
return NULL;
}
ddtdata->size = ddtdata->aifheader.size_debug;
Desk_Debug2_Printf( "DDT info is stored in memory 0x%p-0x%p (%i)\n",
ddtdata->data,
(char*) ddtdata->data + ddtdata->aifheader.size_debug,
ddtdata->aifheader.size_debug
);
fread( ddtdata->data, 1, ddtdata->aifheader.size_debug, file);
fclose( file);
DDT_global_lastddtinfohandle = (DDT_ddtinfo_handle) ddtdata;
return (DDT_ddtinfo_handle) ddtdata;
}
void DDT_DDTInfo( DDT_instruction_info* block, void* ptr)
{
DDT_FindDDTInfoForInstruction( DDT_global_lastddtinfohandle, block, ptr);
}
void DDT_FindDDTInfoForInstruction( DDT_ddtinfo_handle handle, DDT_instruction_info* block, void* ptr)
{
DDT_debugareadata* areadata = (DDT_debugareadata*) handle;
DDT_instruction_info2 info2;
DDT_FindDDTInfoForInstruction2( areadata, &info2, ptr);
block->instruction = info2.instruction;
block->linenumber = info2.pos.linenumber;
block->column = info2.pos.linepos;
strcpy( block->filename, info2.filename);
}
#if 0
{
DDT_section* section;
block->instruction = ptr;
block->filename[0] = 0;
block->linenumber = -1;
block->column = -1;
if ( !areadata) return;
if (!areadata->loaded)
{
/*Debug_Printf( "DDT_DDTInfo - DDT_LoadDDTInfo not previously called.\n");
*/
return;
}
Desk_Debug2_Printf( "DDT_DDTInfo: ddtinfo = %p\n", areadata->data);
if (!areadata->data)
{
Desk_Debug2_Printf( "DDT_DDTInfo: No debugging data...\n");
return;
}
Desk_Debug2_Printf( "CheckDDTInfo\n");
Desk_Debug2_Printf( "debug size is %i\n", areadata->aifheader.size_debug);
Desk_Debug2_Printf( "debug data is at %p\n", areadata->data);
Desk_Debug2_Printf( "debug type is %i\n", areadata->aifheader.debug_type);
Desk_Debug2_Printf( "ddtinfo is loaded at address %p\n", areadata);
/* Scan through all sections looking for code with address 'ptr' */
section = DDT_GetEnclosingSection( (char*) ptr, areadata);
if (!section)
{
Desk_Debug_Printf( "PrintDDTInfo couldn't find enclosing section for instruction %p\n", ptr);
return;
}
#ifdef Desk_DEBUG
{
Desk_Debug_Printf( Desk_error_PLACE "Enclosing section is:\n");
Desk_Debug_Printf( Desk_error_PLACE " language = %i\n", section->flags.data.language);
Desk_Debug_Printf( Desk_error_PLACE " debuglines = %i\n", section->flags.data.debuglines);
Desk_Debug_Printf( Desk_error_PLACE " debugvars = %i\n", section->flags.data.debugvars);
Desk_Debug_Printf( Desk_error_PLACE " -unused- = %i\n", section->flags.data.spare);
Desk_Debug_Printf( Desk_error_PLACE " debugversion= %i\n", section->flags.data.debugversion);
Desk_Debug_Printf( Desk_error_PLACE "\n");
Desk_Debug_Printf( Desk_error_PLACE " codestart = 0x%p\n", section->codeaddr);
Desk_Debug_Printf( Desk_error_PLACE " datastart = 0x%p\n", section->dataaddr);
Desk_Debug_Printf( Desk_error_PLACE " codesize = %i\n", section->codesize);
Desk_Debug_Printf( Desk_error_PLACE " datasize = %i\n", section->datasize);
Desk_Debug_Printf( Desk_error_PLACE " fileinfo = %i\n", section->fileinfo);
Desk_Debug_Printf( Desk_error_PLACE " debugsize = %i\n", section->debugsize);
Desk_Debug_Printf( Desk_error_PLACE "\n");
if ( 0==section->flags.data.language)
{ // This section only contains low level info.
int i;
DDT_symbol* syms = (DDT_symbol*) (section+1);
Desk_Debug_Printf( Desk_error_PLACE " Low-level only. numsyms = %i\n", section->name_or_nsyms.nsyms);
for ( i=0; i<section->name_or_nsyms.nsyms; i++)
{
Desk_Debug_Printf( Desk_error_PLACE "sym %i: stridx=%i, global=%i, symboltype=%i\n",
syms[i].flags.stridx, syms[i].flags.global, syms[i].flags.symboltype
);
}
Desk_Debug_Printf( Desk_error_PLACE "\n");
}
}
#endif
if (!section->fileinfo)
{
Desk_Debug2_Printf( "No file debugging info\n");
return;
}
else
{
DDT_fileinfo* fileinfo = (DDT_fileinfo*) (((char*) section) + section->fileinfo);
/*
int filenamespace = (fileinfo->filename.length + 3) & (~3);
*/
int i;
char* c = &fileinfo->filename.first3[0] + fileinfo->filename.length;
DDT_fileinfo_data* fileinfodata = (DDT_fileinfo_data*) (((int) c+3) & (~3));
DDT_fragment* fragment = (DDT_fragment*) ( fileinfodata+1);
/*Desk_Debug2_Printf( "filenamespace is %i\n", filenamespace);*/
Desk_Debug2_Printf( "PrintDDTI fo: section for instruction %p is %p [0x%p]\n", ptr, section, FILEADDRESS( section));
block->filename[0]=0;
strncat( block->filename, fileinfo->filename.first3, fileinfo->filename.length);
Desk_Debug2_Printf( "\nFilename '%s'\n\n", block->filename);
Desk_Debug2_Printf( "PrintDDTInfo: fileinfo for this section is at offset %i (%p [0x%p]), with %i fragments\n",
section->fileinfo, fileinfo, FILEADDRESS( fileinfo), fileinfodata->n
);
Desk_Debug2_Printf( "Searching file fragments...\n");
for (
i=0;
i < fileinfodata->n;
i++
)
{
DDT_fragment* fragend = (DDT_fragment*) (((char*) fragment) + fragment->fragmentsize);
Desk_Debug_Printf( "fragment 0x%p [0x%p], code=0x%p-0x%p, codesize=%i, fragment size=%i\n",
fragment,
FILEADDRESS( fragment),
fragment->codeaddr,
fragment->codeaddr+fragment->codesize,
fragment->codesize,
fragment->fragmentsize
);
if ( (char*) ptr >= fragment->codeaddr && (char*) ptr < fragment->codeaddr+fragment->codesize)
{
int line = fragment->firstline;
int column = 1;
char* code = fragment->codeaddr;
/*DDT_lineinfo* lineinfo = (DDT_lineinfo*) (fragment+1);
*/
char* lineinfo = (char*) (fragment+1);
Desk_Debug2_Printf( "fragment contains ptr\n");
/* Search through line info for our code pointer */
for ( ; lineinfo < (char*) fragend; )
{
/*DDT_lineinfo* nextlineinfo;*/
char* nextlineinfo;
int lineinc;
int colinc;
int codeinc;
Desk_Debug3_Printf( "DDT_lineinfo at %p [0x%p] is is codeinc %i, lineinc %i\n",
lineinfo, FILEADDRESS( lineinfo), lineinfo[0], lineinfo[1]
);
if ( lineinfo[0]==0 && lineinfo[1]==0)
{
/* 3 half-word form */
/*DDT_lineinfo2* lineinfo2 = (DDT_lineinfo2*) lineinfo;
*/
short int* lineinfo2 = (short int*) lineinfo;
Desk_Debug4_Printf( "Found 3 half-word line info\n");
lineinc = lineinfo2[1];
codeinc = lineinfo2[2];
colinc = -column;
nextlineinfo = lineinfo + 6;
}
else if (lineinfo[0]==0 && lineinfo[1]==64)
{
/* 4 half-word form */
/*DDT_lineinfo3* lineinfo3 = (DDT_lineinfo3*) lineinfo;
*/
short int* lineinfo3 = (short int*) lineinfo;
Desk_Debug4_Printf( "Found 4 half-word line info\n");
lineinc = lineinfo3[1];
codeinc = lineinfo3[2];
colinc = lineinfo3[3] - column;
nextlineinfo = lineinfo + 8;
}
else
{
Desk_Debug4_Printf( "Normal lineinfo.\n");
lineinc = 0;
if (lineinfo[1]<64)
{
Desk_Debug5_Printf( "No column change...\n");
lineinc = lineinfo[1];
colinc = 1-column;
}
else
{
colinc = lineinfo[1]-64;
lineinc = 0;
Desk_Debug5_Printf( "Column change %i\n", colinc);
}
codeinc = lineinfo[0];
nextlineinfo = lineinfo+2;
}
if ( (char*) ptr >= code && (char*) ptr < code+codeinc)
{
Desk_Debug2_Printf( "Instruction at %p is line number %i, column %i\n",
ptr, line, column
);
block->linenumber = line;
block->column = column;
break;
}
Desk_Debug2_Printf( "line %i, column %i, code %p\n", line, column, code);
Desk_Debug2_Printf( "lineinc=%i, columninc=%i, codeinc=%i\n", lineinc, colinc, codeinc);
line += lineinc;
column += colinc;
code += codeinc;
lineinfo = nextlineinfo;
/*Desk_Debug2_Printf( "\n");*/
}
if ( (char*) lineinfo >= (char*) fragend)
{
fprintf( stderr, "Couldn't find source pos for ptr %p\n", ptr);
}
break;
}
fragment = fragend;
}
if ( i == fileinfodata->n) Desk_Debug_Printf( "Couldn't find instruction\n");
}
}
#endif
/*
* Copyright Julian Smith.
*
* This file is part of DDT.
*
* DDT is free software: you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your
* option) any later version.
*
* DDT is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
* Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with DDT. If not, see <http://www.gnu.org/licenses/>.
*/
#include "Desk/Debug.h"
#include "Desk/Error.h"
#include "DDTLib/DDT2.h"
void DDT_FindDDTInfoForInstruction2( DDT_debugareadata* debugarea, DDT_instruction_info2* block, void* instruction)
{
block->instruction = instruction;
block->debugdata = debugarea;
block->section = NULL;
block->proc = NULL;
block->filename[0] = 0;
block->procname[0] = 0;
block->name[0] = 0;
block->pos.linenumber = -1;
block->pos.linepos = -1;
block->symbol.name = NULL;
block->section = DDT_GetEnclosingSection( (char*) instruction, block->debugdata);
if ( !block->section) return;
DDT_CopySectionFilename( block->name, 256, block->section);
block->proc = DDT_GetEnclosingProcedure( (char*) instruction, block->section);
if ( block->proc) DDT_CopyString( block->procname, 256, &block->proc->name);
DDT_GetSourcePos( block, (char*) instruction, block->section);
DDT_FindNearestSymbol( block);
}
void DDT_FindDDTInfoForInstruction3( DDT_ddtinfo_handle debugarea, DDT_instruction_info2* block, void* instruction)
{
DDT_FindDDTInfoForInstruction2( (DDT_debugareadata*) debugarea, block, instruction);
}
/*
* Copyright Julian Smith.
*
* This file is part of DDT.
*
* DDT is free software: you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your
* option) any later version.
*
* DDT is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
* Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with DDT. If not, see <http://www.gnu.org/licenses/>.
*/
#include "Desk/Debug.h"
#include "Desk/Error.h"
#include "DDTLib/DDT2.h"
DDT_procedure* DDT_GetEnclosingProcedure( char* instruction, DDT_section* section)
{
DDT_itemheader* item;
if ( 0==section->flags.data.language)
{
Desk_Debug_Printf( Desk_error_PLACE "DDT_GetEnclosingProcedure called for linker low level section\n");
return NULL;
}
for (
item = &section->header;
(char*) item < (char*) section + section->debugsize;
item = (DDT_itemheader*) ((char*) item + item->itemlength)
)
{
//Desk_Debug3_Printf( Desk_error_PLACE "DDT_GetEnclosingProcedure: looking at item type %i\n", item->itemkind);
if ( (DDT_itemtype) item->itemkind == DDT_itemtype_PROC)
{
DDT_procedure* proc = (DDT_procedure*) item;
DDT_endproc* endproc;
if ( instruction < proc->startaddr) continue;
// Find endproc
endproc = (DDT_endproc*) ((char*) section + proc->endproc);
Desk_Debug_Assert( (DDT_itemtype) endproc->header.itemkind == DDT_itemtype_PROC_END);
if ( instruction >= endproc->endaddr) continue;
// If we reach here, we are in this procedure.
// We don't attempt to cope with nested procedures...
// Find filename according to proc item...
// Doesn't work at all. enclosing section has filename
/*
{
char filename[ 256];
DDT_string* filenamestring = (DDT_string*) ((char*) section + proc->fileentry);
DDT_CopyString( filename, 256, filenamestring);
Desk_Debug3_Printf( "Filename according to proc is '%s'\n", filename);
}
*/
return proc;
}
else
{
//Desk_Debug3_Printf( Desk_error_PLACE "DDT_GetEnclosingProcedure: skipping item type %i\n", item->itemkind);
}
if ( item->itemlength<=0)
{
Desk_Debug_Printf( Desk_error_PLACE "item 0x%p has illegal length %i\n", item, item->itemlength);
break;
}
}
return NULL;
}
/*
* Copyright Julian Smith.
*
* This file is part of DDT.
*
* DDT is free software: you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your
* option) any later version.
*
* DDT is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
* Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with DDT. If not, see <http://www.gnu.org/licenses/>.
*/
#include "Desk/Debug.h"
#include "Desk/Error.h"
#include "DDTLib/DDT2.h"
void DDT_FindNearestSymbol( DDT_instruction_info2* block)
/*
Finds the nearest previous code symbol to block->instruction, in
low-level debugging table section in block.
*/
{
DDT_symbol* syms;
char* stringtable;
int i;
int best_i;
unsigned int best_value;
block->symbol.name = NULL;
if ( block->section->flags.data.language != 0) return;
syms = (DDT_symbol*) (block->section + 1);
stringtable = (char*) ( syms + block->section->name_or_nsyms.nsyms);
best_i = -1;
best_value = 0;
Desk_Debug_Printf( Desk_error_PLACE "Num lowlevel syms = %i\n", block->section->name_or_nsyms.nsyms);
for ( i=0; i<block->section->name_or_nsyms.nsyms; i++) {
//Desk_Debug_Printf( Desk_error_PLACE "sym at 0x%p '%s'\n", (void*) syms[i].value, stringtable + syms[ i].flags.stridx);
if ( syms[i].flags.symboltype==1/*code*/ && (void*) syms[i].value <= block->instruction) {
if ( syms[i].value > best_value) {
best_value = syms[i].value;
best_i = i;
}
}
}
if ( best_i != -1) {
block->symbol.name = stringtable + syms[ best_i].flags.stridx;
block->symbol.symbol = syms[ best_i];
}
}
/*
* Copyright Julian Smith.
*
* This file is part of DDT.
*
* DDT is free software: you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your
* option) any later version.
*
* DDT is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
* Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with DDT. If not, see <http://www.gnu.org/licenses/>.
*/
#include "DDTLib/DDT2.h"
void DDT_PrintDDTInfo_2( DDT_printffn fn, void* reference, DDT_instruction_info2* ddtinfo, const char* separator)
{
if ( ddtinfo->section)
{
DDT_sourcepos nullpos = { -1, -1}; // These are unsigned really.
if ( ddtinfo->name[0])
fn( reference, "Module name '%s'. %s", ddtinfo->name, separator);
else fn( reference, "Module name unknown. %s", separator);
if ( ddtinfo->pos.linenumber != nullpos.linenumber)
fn( reference, "File '%s', line %4i, column %3i. %s",
ddtinfo->filename,
ddtinfo->pos.linenumber,
ddtinfo->pos.linepos,
separator
);
else if ( ddtinfo->filename[0])
fn( reference, "File '%s' (no line-number information available). %s",
ddtinfo->filename,
separator
);
if ( ddtinfo->symbol.name)
fn( reference,
"Offset %4i bytes after %s code-symbol '%s' (from linker's debugging data). %s",
(char*) ddtinfo->instruction - (char*) ddtinfo->symbol.symbol.value,
(ddtinfo->symbol.symbol.flags.global) ? "global" : "local ",
ddtinfo->symbol.name,
separator
);
if ( ddtinfo->proc)
fn( reference,
"Proc/fn '%s', offset %4i. %s",
ddtinfo->procname,
(char*) ddtinfo->instruction - (char*) ddtinfo->proc->startaddr,
separator
);
else fn( reference, "No proc/fn information. %s", separator);
}
else fn( reference, "No DDT information available. %s", separator);
}
void DDT_PrintDDTInfo_1( DDT_printffn fn, void* reference, DDT_instruction_info2* ddtinfo)
{
DDT_PrintDDTInfo_2( fn, reference, ddtinfo, "");
}
/*
* Copyright Julian Smith.
*
* This file is part of DDT.
*
* DDT is free software: you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your
* option) any later version.
*
* DDT is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
* Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with DDT. If not, see <http://www.gnu.org/licenses/>.
*/
#include <string.h>
#include "Desk/Debug.h"
#include "Desk/Error.h"
#include "DDTLib/DDT2.h"
void DDT_CopyString( char* buffer, int buflen,DDT_string* string)
{
buffer[0] = 0;
if ( string->length >= buflen) return;
strncat( buffer, string->first3, string->length);
}
void DDT_CopySectionFilename( char* buffer, int buflen, DDT_section* section)
{
if ( section->flags.data.language==0)
{
buffer[0] = 0; // Low-level only, so no filename.
}
else
{
DDT_CopyString( buffer, buflen, &section->name_or_nsyms.name);
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment