mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-06-13 04:38:24 +00:00
Adding basic support for Dwarf line number debug information.
I promise to keep future commits smaller. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@25396 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@ -10,17 +10,83 @@
|
||||
// Collect debug information for a module. This information should be in a
|
||||
// neutral form that can be used by different debugging schemes.
|
||||
//
|
||||
// The organization of information is primarily clustered around the source
|
||||
// compile units. The main exception is source line coorespondence where
|
||||
// inlining may interleave code from various compile units.
|
||||
//
|
||||
// The following information can be retrieved from the MachineDebugInfo.
|
||||
//
|
||||
// -- Source directories - Directories are uniqued based on their canonical
|
||||
// string and assigned a sequential numeric ID (base 1.) A directory ID - 1
|
||||
// provides the index of directory information in a queried directory list.
|
||||
// -- Source files - Files are also uniqued based on their name and directory
|
||||
// ID. A file ID is sequential number (base 1.) A file ID - 1 provides the
|
||||
// index of source information in a queried file list.
|
||||
// -- Source line coorespondence - A vector of file ID, line#, column# triples.
|
||||
// A DEBUG_LOCATION instruction is generated by the DAG Legalizer
|
||||
// corresponding to each entry in the source line list. This allows a debug
|
||||
// information emitter to generate labels to map code addressed to debug
|
||||
// tables.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef LLVM_CODEGEN_MACHINEDEBUGINFO_H
|
||||
#define LLVM_CODEGEN_MACHINEDEBUGINFO_H
|
||||
|
||||
#include "llvm/Pass.h"
|
||||
#include "llvm/ADT/UniqueVector.h"
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
|
||||
namespace llvm {
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
/// SourceLineInfo - This class is used to record source line correspondence.
|
||||
///
|
||||
class SourceLineInfo {
|
||||
private:
|
||||
unsigned Line; // Source line number.
|
||||
unsigned Column; // Source column.
|
||||
unsigned SourceID; // Source ID number.
|
||||
|
||||
public:
|
||||
SourceLineInfo(unsigned L, unsigned C, unsigned S)
|
||||
: Line(L), Column(C), SourceID(S) {}
|
||||
|
||||
// Accessors
|
||||
unsigned getLine() const { return Line; }
|
||||
unsigned getColumn() const { return Column; }
|
||||
unsigned getSourceID() const { return SourceID; }
|
||||
};
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
/// SourceFileInfo - This class is used to track source information.
|
||||
///
|
||||
class SourceFileInfo {
|
||||
private:
|
||||
unsigned DirectoryID; // Directory ID number.
|
||||
std::string Name; // File name (not including directory.)
|
||||
|
||||
public:
|
||||
SourceFileInfo(unsigned D, const std::string &N) : DirectoryID(D), Name(N) {}
|
||||
|
||||
// Accessors
|
||||
unsigned getDirectoryID() const { return DirectoryID; }
|
||||
const std::string &getName() const { return Name; }
|
||||
|
||||
/// operator== - Used by UniqueVector to locate entry.
|
||||
///
|
||||
bool operator==(const SourceFileInfo &SI) const {
|
||||
return getDirectoryID() == SI.getDirectoryID() && getName() == SI.getName();
|
||||
}
|
||||
|
||||
/// operator< - Used by UniqueVector to locate entry.
|
||||
///
|
||||
bool operator<(const SourceFileInfo &SI) const {
|
||||
return getDirectoryID() < SI.getDirectoryID() ||
|
||||
(getDirectoryID() == SI.getDirectoryID() && getName() < SI.getName());
|
||||
}
|
||||
};
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
/// MachineDebugInfo - This class contains debug information specific to a
|
||||
/// module. Queries can be made by different debugging schemes and reformated
|
||||
@ -28,48 +94,70 @@ namespace llvm {
|
||||
///
|
||||
class MachineDebugInfo : public ImmutablePass {
|
||||
private:
|
||||
std::map<std::string, unsigned> SourceMap; // Map of source file path to id
|
||||
unsigned SourceCount; // Number of source files (used to
|
||||
// generate id)
|
||||
unsigned UniqueID; // Number used to unique labels used
|
||||
// by debugger.
|
||||
// DirectoryMap - UniqueVector for directories.
|
||||
UniqueVector<std::string> Directories;
|
||||
|
||||
// SourceMap - UniqueVector for source files.
|
||||
UniqueVector<SourceFileInfo> SourceFiles;
|
||||
|
||||
// Lines - List of of source line correspondence.
|
||||
std::vector<SourceLineInfo *> Lines;
|
||||
|
||||
public:
|
||||
// Ctor.
|
||||
MachineDebugInfo()
|
||||
: SourceMap()
|
||||
, SourceCount(0)
|
||||
, UniqueID(1)
|
||||
: Directories()
|
||||
, SourceFiles()
|
||||
, Lines()
|
||||
{}
|
||||
~MachineDebugInfo() { }
|
||||
|
||||
/// hasInfo - Returns true if debug info is present.
|
||||
/// doInitialization - Initialize the debug state for a new module.
|
||||
///
|
||||
// FIXME - need scheme to suppress debug output.
|
||||
bool hasInfo() const { return SourceCount != 0; }
|
||||
|
||||
/// getNextUniqueID - Returns a unique number for labels used by debugger.
|
||||
///
|
||||
unsigned getNextUniqueID() { return UniqueID++; }
|
||||
|
||||
/// RecordLabel - Records location information and associates it with a
|
||||
/// debug label. Returns unique label id.
|
||||
unsigned RecordLabel(unsigned Line, unsigned Col, unsigned SrcFile) {
|
||||
// FIXME - actually record.
|
||||
return getNextUniqueID();
|
||||
}
|
||||
|
||||
bool doInitialization();
|
||||
|
||||
|
||||
/// doFinalization - Tear down the debug state after completion of a module.
|
||||
///
|
||||
bool doFinalization();
|
||||
|
||||
/// getUniqueSourceID - Register a source file with debug info. Returns an id.
|
||||
/// hasInfo - Returns true if debug info is present.
|
||||
///
|
||||
unsigned getUniqueSourceID(const std::string &fname,
|
||||
const std::string &dirname);
|
||||
// FIXME - need proper scheme to suppress debug output.
|
||||
bool hasInfo() const { return !SourceFiles.empty(); }
|
||||
|
||||
/// getSourceFiles - Return a vector of files. Vector index + 1 equals id.
|
||||
/// RecordLabel - Records location information and associates it with a
|
||||
/// debug label. Returns a unique label ID used to generate a label and
|
||||
/// provide correspondence to the source line list.
|
||||
unsigned RecordLabel(unsigned Line, unsigned Column, unsigned Source) {
|
||||
Lines.push_back(new SourceLineInfo(Line, Column, Source));
|
||||
return Lines.size();
|
||||
}
|
||||
|
||||
/// RecordSource - Register a source file with debug info. Returns an source
|
||||
/// ID.
|
||||
unsigned RecordSource(const std::string &Directory,
|
||||
const std::string &Source) {
|
||||
unsigned DirectoryID = Directories.insert(Directory);
|
||||
return SourceFiles.insert(SourceFileInfo(DirectoryID, Source));
|
||||
}
|
||||
|
||||
/// getDirectories - Return the UniqueVector of std::string representing
|
||||
/// directories.
|
||||
const UniqueVector<std::string> &getDirectories() const {
|
||||
return Directories;
|
||||
}
|
||||
|
||||
/// getSourceFiles - Return the UniqueVector of source files.
|
||||
///
|
||||
std::vector<std::string> getSourceFiles() const;
|
||||
const UniqueVector<SourceFileInfo> &getSourceFiles() const {
|
||||
return SourceFiles;
|
||||
}
|
||||
|
||||
/// getSourceLines - Return a vector of source lines. Vector index + 1
|
||||
/// equals label ID.
|
||||
const std::vector<SourceLineInfo *> &getSourceLines() const {
|
||||
return Lines;
|
||||
}
|
||||
|
||||
}; // End class MachineDebugInfo
|
||||
|
||||
|
Reference in New Issue
Block a user