mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-01-14 16:33:28 +00:00
remove llvm-db: it is completely broken and if anyone wants to do a debugger,
they should not base it on llvm-db (which not following almost any "best practices"). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@83288 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
c758feca8a
commit
dbf75e813e
@ -301,7 +301,6 @@ add_subdirectory(lib/ExecutionEngine/Interpreter)
|
||||
add_subdirectory(lib/ExecutionEngine/JIT)
|
||||
add_subdirectory(lib/Target)
|
||||
add_subdirectory(lib/AsmParser)
|
||||
add_subdirectory(lib/Debugger)
|
||||
add_subdirectory(lib/Archive)
|
||||
|
||||
add_subdirectory(projects)
|
||||
|
@ -1,176 +0,0 @@
|
||||
//===- Debugger.h - LLVM debugger library interface -------------*- C++ -*-===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This file defines the LLVM source-level debugger library interface.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef LLVM_DEBUGGER_DEBUGGER_H
|
||||
#define LLVM_DEBUGGER_DEBUGGER_H
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace llvm {
|
||||
class Module;
|
||||
class InferiorProcess;
|
||||
class LLVMContext;
|
||||
|
||||
/// Debugger class - This class implements the LLVM source-level debugger.
|
||||
/// This allows clients to handle the user IO processing without having to
|
||||
/// worry about how the debugger itself works.
|
||||
///
|
||||
class Debugger {
|
||||
// State the debugger needs when starting and stopping the program.
|
||||
std::vector<std::string> ProgramArguments;
|
||||
|
||||
// The environment to run the program with. This should eventually be
|
||||
// changed to vector of strings when we allow the user to edit the
|
||||
// environment.
|
||||
const char * const *Environment;
|
||||
|
||||
// Program - The currently loaded program, or null if none is loaded.
|
||||
Module *Program;
|
||||
|
||||
// Process - The currently executing inferior process.
|
||||
InferiorProcess *Process;
|
||||
|
||||
Debugger(const Debugger &); // DO NOT IMPLEMENT
|
||||
void operator=(const Debugger &); // DO NOT IMPLEMENT
|
||||
public:
|
||||
Debugger();
|
||||
~Debugger();
|
||||
|
||||
//===------------------------------------------------------------------===//
|
||||
// Methods for manipulating and inspecting the execution environment.
|
||||
//
|
||||
|
||||
/// initializeEnvironment - Specify the environment the program should run
|
||||
/// with. This is used to initialize the environment of the program to the
|
||||
/// environment of the debugger.
|
||||
void initializeEnvironment(const char *const *envp) {
|
||||
Environment = envp;
|
||||
}
|
||||
|
||||
/// setWorkingDirectory - Specify the working directory for the program to
|
||||
/// be started from.
|
||||
void setWorkingDirectory(const std::string &Dir) {
|
||||
// FIXME: implement
|
||||
}
|
||||
|
||||
template<typename It>
|
||||
void setProgramArguments(It I, It E) {
|
||||
ProgramArguments.assign(I, E);
|
||||
}
|
||||
unsigned getNumProgramArguments() const {
|
||||
return static_cast<unsigned>(ProgramArguments.size());
|
||||
}
|
||||
const std::string &getProgramArgument(unsigned i) const {
|
||||
return ProgramArguments[i];
|
||||
}
|
||||
|
||||
|
||||
//===------------------------------------------------------------------===//
|
||||
// Methods for manipulating and inspecting the program currently loaded.
|
||||
//
|
||||
|
||||
/// isProgramLoaded - Return true if there is a program currently loaded.
|
||||
///
|
||||
bool isProgramLoaded() const { return Program != 0; }
|
||||
|
||||
/// getProgram - Return the LLVM module corresponding to the program.
|
||||
///
|
||||
Module *getProgram() const { return Program; }
|
||||
|
||||
/// getProgramPath - Get the path of the currently loaded program, or an
|
||||
/// empty string if none is loaded.
|
||||
std::string getProgramPath() const;
|
||||
|
||||
/// loadProgram - If a program is currently loaded, unload it. Then search
|
||||
/// the PATH for the specified program, loading it when found. If the
|
||||
/// specified program cannot be found, an exception is thrown to indicate
|
||||
/// the error.
|
||||
void loadProgram(const std::string &Path, LLVMContext& Context);
|
||||
|
||||
/// unloadProgram - If a program is running, kill it, then unload all traces
|
||||
/// of the current program. If no program is loaded, this method silently
|
||||
/// succeeds.
|
||||
void unloadProgram();
|
||||
|
||||
//===------------------------------------------------------------------===//
|
||||
// Methods for manipulating and inspecting the program currently running.
|
||||
//
|
||||
// If the program is running, and the debugger is active, then we know that
|
||||
// the program has stopped. This being the case, we can inspect the
|
||||
// program, ask it for its source location, set breakpoints, etc.
|
||||
//
|
||||
|
||||
/// isProgramRunning - Return true if a program is loaded and has a
|
||||
/// currently active instance.
|
||||
bool isProgramRunning() const { return Process != 0; }
|
||||
|
||||
/// getRunningProcess - If there is no program running, throw an exception.
|
||||
/// Otherwise return the running process so that it can be inspected by the
|
||||
/// debugger.
|
||||
const InferiorProcess &getRunningProcess() const {
|
||||
if (Process == 0) throw "No process running.";
|
||||
return *Process;
|
||||
}
|
||||
|
||||
/// createProgram - Create an instance of the currently loaded program,
|
||||
/// killing off any existing one. This creates the program and stops it at
|
||||
/// the first possible moment. If there is no program loaded or if there is
|
||||
/// a problem starting the program, this method throws an exception.
|
||||
void createProgram();
|
||||
|
||||
/// killProgram - If the program is currently executing, kill off the
|
||||
/// process and free up any state related to the currently running program.
|
||||
/// If there is no program currently running, this just silently succeeds.
|
||||
/// If something horrible happens when killing the program, an exception
|
||||
/// gets thrown.
|
||||
void killProgram();
|
||||
|
||||
|
||||
//===------------------------------------------------------------------===//
|
||||
// Methods for continuing execution. These methods continue the execution
|
||||
// of the program by some amount. If the program is successfully stopped,
|
||||
// execution returns, otherwise an exception is thrown.
|
||||
//
|
||||
// NOTE: These methods should always be used in preference to directly
|
||||
// accessing the Dbg object, because these will delete the Process object if
|
||||
// the process unexpectedly dies.
|
||||
//
|
||||
|
||||
/// stepProgram - Implement the 'step' command, continuing execution until
|
||||
/// the next possible stop point.
|
||||
void stepProgram();
|
||||
|
||||
/// nextProgram - Implement the 'next' command, continuing execution until
|
||||
/// the next possible stop point that is in the current function.
|
||||
void nextProgram();
|
||||
|
||||
/// finishProgram - Implement the 'finish' command, continuing execution
|
||||
/// until the specified frame ID returns.
|
||||
void finishProgram(void *Frame);
|
||||
|
||||
/// contProgram - Implement the 'cont' command, continuing execution until
|
||||
/// the next breakpoint is encountered.
|
||||
void contProgram();
|
||||
};
|
||||
|
||||
class NonErrorException {
|
||||
std::string Message;
|
||||
public:
|
||||
NonErrorException(const std::string &M) : Message(M) {}
|
||||
const std::string &getMessage() const { return Message; }
|
||||
};
|
||||
|
||||
} // end namespace llvm
|
||||
|
||||
#endif
|
@ -1,137 +0,0 @@
|
||||
//===- InferiorProcess.h - Represent the program being debugged -*- C++ -*-===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This file defines the InferiorProcess class, which is used to represent,
|
||||
// inspect, and manipulate a process under the control of the LLVM debugger.
|
||||
//
|
||||
// This is an abstract class which should allow various different types of
|
||||
// implementations. Initially we implement a unix specific debugger backend
|
||||
// that does not require code generator support, but we could eventually use
|
||||
// code generator support with ptrace, support windows based targets, supported
|
||||
// remote targets, etc.
|
||||
//
|
||||
// If the inferior process unexpectedly dies, an attempt to communicate with it
|
||||
// will cause an InferiorProcessDead exception to be thrown, indicating the exit
|
||||
// code of the process. When this occurs, no methods on the InferiorProcess
|
||||
// class should be called except for the destructor.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef LLVM_DEBUGGER_INFERIORPROCESS_H
|
||||
#define LLVM_DEBUGGER_INFERIORPROCESS_H
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace llvm {
|
||||
class Module;
|
||||
class GlobalVariable;
|
||||
|
||||
/// InferiorProcessDead exception - This class is thrown by methods that
|
||||
/// communicate with the interior process if the process unexpectedly exits or
|
||||
/// dies. The instance variable indicates what the exit code of the process
|
||||
/// was, or -1 if unknown.
|
||||
class InferiorProcessDead {
|
||||
int ExitCode;
|
||||
public:
|
||||
InferiorProcessDead(int EC) : ExitCode(EC) {}
|
||||
int getExitCode() const { return ExitCode; }
|
||||
};
|
||||
|
||||
/// InferiorProcess class - This class represents the process being debugged
|
||||
/// by the debugger. Objects of this class should not be stack allocated,
|
||||
/// because the destructor can throw exceptions.
|
||||
///
|
||||
class InferiorProcess {
|
||||
Module *M;
|
||||
protected:
|
||||
InferiorProcess(Module *m) : M(m) {}
|
||||
public:
|
||||
/// create - Create an inferior process of the specified module, and
|
||||
/// stop it at the first opportunity. If there is a problem starting the
|
||||
/// program (for example, it has no main), throw an exception.
|
||||
static InferiorProcess *create(Module *M,
|
||||
const std::vector<std::string> &Arguments,
|
||||
const char * const *envp);
|
||||
|
||||
// InferiorProcess destructor - Kill the current process. If something
|
||||
// terrible happens, we throw an exception from the destructor.
|
||||
virtual ~InferiorProcess() {}
|
||||
|
||||
//===------------------------------------------------------------------===//
|
||||
// Status methods - These methods return information about the currently
|
||||
// stopped process.
|
||||
//
|
||||
|
||||
/// getStatus - Return a status message that is specific to the current type
|
||||
/// of inferior process that is created. This can return things like the
|
||||
/// PID of the inferior or other potentially interesting things.
|
||||
virtual std::string getStatus() const {
|
||||
return "";
|
||||
}
|
||||
|
||||
//===------------------------------------------------------------------===//
|
||||
// Methods for inspecting the call stack.
|
||||
//
|
||||
|
||||
/// getPreviousFrame - Given the descriptor for the current stack frame,
|
||||
/// return the descriptor for the caller frame. This returns null when it
|
||||
/// runs out of frames. If Frame is null, the initial frame should be
|
||||
/// returned.
|
||||
virtual void *getPreviousFrame(void *Frame) const = 0;
|
||||
|
||||
/// getSubprogramDesc - Return the subprogram descriptor for the current
|
||||
/// stack frame.
|
||||
virtual const GlobalVariable *getSubprogramDesc(void *Frame) const = 0;
|
||||
|
||||
/// getFrameLocation - This method returns the source location where each
|
||||
/// stack frame is stopped.
|
||||
virtual void getFrameLocation(void *Frame, unsigned &LineNo,
|
||||
unsigned &ColNo,
|
||||
const GlobalVariable *&SourceDesc) const = 0;
|
||||
|
||||
//===------------------------------------------------------------------===//
|
||||
// Methods for manipulating breakpoints.
|
||||
//
|
||||
|
||||
/// addBreakpoint - This method adds a breakpoint at the specified line,
|
||||
/// column, and source file, and returns a unique identifier for it.
|
||||
///
|
||||
/// It is up to the debugger to determine whether or not there is actually a
|
||||
/// stop-point that corresponds with the specified location.
|
||||
virtual unsigned addBreakpoint(unsigned LineNo, unsigned ColNo,
|
||||
const GlobalVariable *SourceDesc) = 0;
|
||||
|
||||
/// removeBreakpoint - This deletes the breakpoint with the specified ID
|
||||
/// number.
|
||||
virtual void removeBreakpoint(unsigned ID) = 0;
|
||||
|
||||
|
||||
//===------------------------------------------------------------------===//
|
||||
// Execution methods - These methods cause the program to continue execution
|
||||
// by some amount. If the program successfully stops, this returns.
|
||||
// Otherwise, if the program unexpectedly terminates, an InferiorProcessDead
|
||||
// exception is thrown.
|
||||
//
|
||||
|
||||
/// stepProgram - Implement the 'step' command, continuing execution until
|
||||
/// the next possible stop point.
|
||||
virtual void stepProgram() = 0;
|
||||
|
||||
/// finishProgram - Implement the 'finish' command, continuing execution
|
||||
/// until the current function returns.
|
||||
virtual void finishProgram(void *Frame) = 0;
|
||||
|
||||
/// contProgram - Implement the 'cont' command, continuing execution until
|
||||
/// a breakpoint is encountered.
|
||||
virtual void contProgram() = 0;
|
||||
};
|
||||
} // end namespace llvm
|
||||
|
||||
#endif
|
@ -1,246 +0,0 @@
|
||||
//===- ProgramInfo.h - Information about the loaded program -----*- C++ -*-===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This file defines various pieces of information about the currently loaded
|
||||
// program. One instance of this object is created every time a program is
|
||||
// loaded, and destroyed every time it is unloaded.
|
||||
//
|
||||
// The various pieces of information gathered about the source program are all
|
||||
// designed to be extended by various SourceLanguage implementations. This
|
||||
// allows source languages to keep any extended information that they support in
|
||||
// the derived class portions of the class.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef LLVM_DEBUGGER_PROGRAMINFO_H
|
||||
#define LLVM_DEBUGGER_PROGRAMINFO_H
|
||||
|
||||
#include "llvm/System/TimeValue.h"
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
|
||||
namespace llvm {
|
||||
class GlobalVariable;
|
||||
class Module;
|
||||
class SourceFile;
|
||||
struct SourceLanguage;
|
||||
class ProgramInfo;
|
||||
|
||||
/// SourceLanguageCache - SourceLanguage implementations are allowed to cache
|
||||
/// stuff in the ProgramInfo object. The only requirement we have on these
|
||||
/// instances is that they are destroyable.
|
||||
struct SourceLanguageCache {
|
||||
virtual ~SourceLanguageCache() {}
|
||||
};
|
||||
|
||||
/// SourceFileInfo - One instance of this structure is created for each
|
||||
/// source file in the program.
|
||||
///
|
||||
class SourceFileInfo {
|
||||
/// BaseName - The filename of the source file.
|
||||
std::string BaseName;
|
||||
|
||||
/// Directory - The working directory of this source file when it was
|
||||
/// compiled.
|
||||
std::string Directory;
|
||||
|
||||
/// Version - The version of the LLVM debug information that this file was
|
||||
/// compiled with.
|
||||
unsigned Version;
|
||||
|
||||
/// Language - The source language that the file was compiled with. This
|
||||
/// pointer is never null.
|
||||
///
|
||||
const SourceLanguage *Language;
|
||||
|
||||
/// Descriptor - The LLVM Global Variable which describes the source file.
|
||||
///
|
||||
const GlobalVariable *Descriptor;
|
||||
|
||||
/// SourceText - The body of this source file, or null if it has not yet
|
||||
/// been loaded.
|
||||
mutable SourceFile *SourceText;
|
||||
public:
|
||||
SourceFileInfo(const GlobalVariable *Desc, const SourceLanguage &Lang);
|
||||
~SourceFileInfo();
|
||||
|
||||
const std::string &getBaseName() const { return BaseName; }
|
||||
const std::string &getDirectory() const { return Directory; }
|
||||
unsigned getDebugVersion() const { return Version; }
|
||||
const GlobalVariable *getDescriptor() const { return Descriptor; }
|
||||
SourceFile &getSourceText() const;
|
||||
|
||||
const SourceLanguage &getLanguage() const { return *Language; }
|
||||
};
|
||||
|
||||
|
||||
/// SourceFunctionInfo - An instance of this class is used to represent each
|
||||
/// source function in the program.
|
||||
///
|
||||
class SourceFunctionInfo {
|
||||
/// Name - This contains an abstract name that is potentially useful to the
|
||||
/// end-user. If there is no explicit support for the current language,
|
||||
/// then this string is used to identify the function.
|
||||
std::string Name;
|
||||
|
||||
/// Descriptor - The descriptor for this function.
|
||||
///
|
||||
const GlobalVariable *Descriptor;
|
||||
|
||||
/// SourceFile - The file that this function is defined in.
|
||||
///
|
||||
const SourceFileInfo *SourceFile;
|
||||
|
||||
/// LineNo, ColNo - The location of the first stop-point in the function.
|
||||
/// These are computed on demand.
|
||||
mutable unsigned LineNo, ColNo;
|
||||
|
||||
public:
|
||||
SourceFunctionInfo(ProgramInfo &PI, const GlobalVariable *Desc);
|
||||
virtual ~SourceFunctionInfo() {}
|
||||
|
||||
/// getSymbolicName - Return a human-readable symbolic name to identify the
|
||||
/// function (for example, in stack traces).
|
||||
virtual std::string getSymbolicName() const { return Name; }
|
||||
|
||||
/// getDescriptor - This returns the descriptor for the function.
|
||||
///
|
||||
const GlobalVariable *getDescriptor() const { return Descriptor; }
|
||||
|
||||
/// getSourceFile - This returns the source file that defines the function.
|
||||
///
|
||||
const SourceFileInfo &getSourceFile() const { return *SourceFile; }
|
||||
|
||||
/// getSourceLocation - This method returns the location of the first
|
||||
/// stopping point in the function. If the body of the function cannot be
|
||||
/// found, this returns zeros for both values.
|
||||
void getSourceLocation(unsigned &LineNo, unsigned &ColNo) const;
|
||||
};
|
||||
|
||||
|
||||
/// ProgramInfo - This object contains information about the loaded program.
|
||||
/// When a new program is loaded, an instance of this class is created. When
|
||||
/// the program is unloaded, the instance is destroyed. This object basically
|
||||
/// manages the lazy computation of information useful for the debugger.
|
||||
class ProgramInfo {
|
||||
Module *M;
|
||||
|
||||
/// ProgramTimeStamp - This is the timestamp of the executable file that we
|
||||
/// currently have loaded into the debugger.
|
||||
sys::TimeValue ProgramTimeStamp;
|
||||
|
||||
/// SourceFiles - This map is used to transform source file descriptors into
|
||||
/// their corresponding SourceFileInfo objects. This mapping owns the
|
||||
/// memory for the SourceFileInfo objects.
|
||||
///
|
||||
bool SourceFilesIsComplete;
|
||||
std::map<const GlobalVariable*, SourceFileInfo*> SourceFiles;
|
||||
|
||||
/// SourceFileIndex - Mapping from source file basenames to the information
|
||||
/// about the file. Note that there can be filename collisions, so this is
|
||||
/// a multimap. This map is populated incrementally as the user interacts
|
||||
/// with the program, through the getSourceFileFromDesc method. If ALL of
|
||||
/// the source files are needed, the getSourceFiles() method scans the
|
||||
/// entire program looking for them.
|
||||
///
|
||||
std::multimap<std::string, SourceFileInfo*> SourceFileIndex;
|
||||
|
||||
/// SourceFunctions - This map contains entries functions in the source
|
||||
/// program. If SourceFunctionsIsComplete is true, then this is ALL of the
|
||||
/// functions in the program are in this map.
|
||||
bool SourceFunctionsIsComplete;
|
||||
std::map<const GlobalVariable*, SourceFunctionInfo*> SourceFunctions;
|
||||
|
||||
/// LanguageCaches - Each source language is permitted to keep a per-program
|
||||
/// cache of information specific to whatever it needs. This vector is
|
||||
/// effectively a small map from the languages that are active in the
|
||||
/// program to their caches. This can be accessed by the language by the
|
||||
/// "getLanguageCache" method.
|
||||
std::vector<std::pair<const SourceLanguage*,
|
||||
SourceLanguageCache*> > LanguageCaches;
|
||||
public:
|
||||
ProgramInfo(Module *m);
|
||||
~ProgramInfo();
|
||||
|
||||
/// getProgramTimeStamp - Return the time-stamp of the program when it was
|
||||
/// loaded.
|
||||
sys::TimeValue getProgramTimeStamp() const { return ProgramTimeStamp; }
|
||||
|
||||
//===------------------------------------------------------------------===//
|
||||
// Interfaces to the source code files that make up the program.
|
||||
//
|
||||
|
||||
/// getSourceFile - Return source file information for the specified source
|
||||
/// file descriptor object, adding it to the collection as needed. This
|
||||
/// method always succeeds (is unambiguous), and is always efficient.
|
||||
///
|
||||
const SourceFileInfo &getSourceFile(const GlobalVariable *Desc);
|
||||
|
||||
/// getSourceFile - Look up the file with the specified name. If there is
|
||||
/// more than one match for the specified filename, prompt the user to pick
|
||||
/// one. If there is no source file that matches the specified name, throw
|
||||
/// an exception indicating that we can't find the file. Otherwise, return
|
||||
/// the file information for that file.
|
||||
///
|
||||
/// If the source file hasn't been discovered yet in the program, this
|
||||
/// method might have to index the whole program by calling the
|
||||
/// getSourceFiles() method.
|
||||
///
|
||||
const SourceFileInfo &getSourceFile(const std::string &Filename);
|
||||
|
||||
/// getSourceFiles - Index all of the source files in the program and return
|
||||
/// them. This information is lazily computed the first time that it is
|
||||
/// requested. Since this information can take a long time to compute, the
|
||||
/// user is given a chance to cancel it. If this occurs, an exception is
|
||||
/// thrown.
|
||||
const std::map<const GlobalVariable*, SourceFileInfo*> &
|
||||
getSourceFiles(bool RequiresCompleteMap = true);
|
||||
|
||||
//===------------------------------------------------------------------===//
|
||||
// Interfaces to the functions that make up the program.
|
||||
//
|
||||
|
||||
/// getFunction - Return source function information for the specified
|
||||
/// function descriptor object, adding it to the collection as needed. This
|
||||
/// method always succeeds (is unambiguous), and is always efficient.
|
||||
///
|
||||
const SourceFunctionInfo &getFunction(const GlobalVariable *Desc);
|
||||
|
||||
/// getSourceFunctions - Index all of the functions in the program and
|
||||
/// return them. This information is lazily computed the first time that it
|
||||
/// is requested. Since this information can take a long time to compute,
|
||||
/// the user is given a chance to cancel it. If this occurs, an exception
|
||||
/// is thrown.
|
||||
const std::map<const GlobalVariable*, SourceFunctionInfo*> &
|
||||
getSourceFunctions(bool RequiresCompleteMap = true);
|
||||
|
||||
/// addSourceFunctionsRead - Return true if the source functions map is
|
||||
/// complete: that is, all functions in the program have been read in.
|
||||
bool allSourceFunctionsRead() const { return SourceFunctionsIsComplete; }
|
||||
|
||||
/// getLanguageCache - This method is used to build per-program caches of
|
||||
/// information, such as the functions or types visible to the program.
|
||||
/// This can be used by SourceLanguage implementations because it requires
|
||||
/// an accessible [sl]::CacheType typedef, where [sl] is the C++ type of the
|
||||
/// source-language subclass.
|
||||
template<typename SL>
|
||||
typename SL::CacheType &getLanguageCache(const SL *L) {
|
||||
for (unsigned i = 0, e = LanguageCaches.size(); i != e; ++i)
|
||||
if (LanguageCaches[i].first == L)
|
||||
return *(typename SL::CacheType*)LanguageCaches[i].second;
|
||||
typename SL::CacheType *NewCache = L->createSourceLanguageCache(*this);
|
||||
LanguageCaches.push_back(std::make_pair(L, NewCache));
|
||||
return *NewCache;
|
||||
}
|
||||
};
|
||||
|
||||
} // end namespace llvm
|
||||
|
||||
#endif
|
@ -1,142 +0,0 @@
|
||||
//===- RuntimeInfo.h - Information about running program --------*- C++ -*-===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This file defines classes that capture various pieces of information about
|
||||
// the currently executing, but stopped, program. One instance of this object
|
||||
// is created every time a program is stopped, and destroyed every time it
|
||||
// starts running again. This object's main goal is to make access to runtime
|
||||
// information easy and efficient, by caching information as requested.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef LLVM_DEBUGGER_RUNTIMEINFO_H
|
||||
#define LLVM_DEBUGGER_RUNTIMEINFO_H
|
||||
|
||||
#include <vector>
|
||||
#include <cassert>
|
||||
|
||||
namespace llvm {
|
||||
class ProgramInfo;
|
||||
class RuntimeInfo;
|
||||
class InferiorProcess;
|
||||
class GlobalVariable;
|
||||
class SourceFileInfo;
|
||||
|
||||
/// StackFrame - One instance of this structure is created for each stack
|
||||
/// frame that is active in the program.
|
||||
///
|
||||
class StackFrame {
|
||||
RuntimeInfo &RI;
|
||||
void *FrameID;
|
||||
const GlobalVariable *FunctionDesc;
|
||||
|
||||
/// LineNo, ColNo, FileInfo - This information indicates WHERE in the source
|
||||
/// code for the program the stack frame is located.
|
||||
unsigned LineNo, ColNo;
|
||||
const SourceFileInfo *SourceInfo;
|
||||
public:
|
||||
StackFrame(RuntimeInfo &RI, void *ParentFrameID);
|
||||
|
||||
StackFrame &operator=(const StackFrame &RHS) {
|
||||
FrameID = RHS.FrameID;
|
||||
FunctionDesc = RHS.FunctionDesc;
|
||||
return *this;
|
||||
}
|
||||
|
||||
/// getFrameID - return the low-level opaque frame ID of this stack frame.
|
||||
///
|
||||
void *getFrameID() const { return FrameID; }
|
||||
|
||||
/// getFunctionDesc - Return the descriptor for the function that contains
|
||||
/// this stack frame, or null if it is unknown.
|
||||
///
|
||||
const GlobalVariable *getFunctionDesc();
|
||||
|
||||
/// getSourceLocation - Return the source location that this stack frame is
|
||||
/// sitting at.
|
||||
void getSourceLocation(unsigned &LineNo, unsigned &ColNo,
|
||||
const SourceFileInfo *&SourceInfo);
|
||||
};
|
||||
|
||||
|
||||
/// RuntimeInfo - This class collects information about the currently running
|
||||
/// process. It is created whenever the program stops execution for the
|
||||
/// debugger, and destroyed whenver execution continues.
|
||||
class RuntimeInfo {
|
||||
/// ProgInfo - This object contains static information about the program.
|
||||
///
|
||||
ProgramInfo *ProgInfo;
|
||||
|
||||
/// IP - This object contains information about the actual inferior process
|
||||
/// that we are communicating with and aggregating information from.
|
||||
const InferiorProcess &IP;
|
||||
|
||||
/// CallStack - This caches information about the current stack trace of the
|
||||
/// program. This is lazily computed as needed.
|
||||
std::vector<StackFrame> CallStack;
|
||||
|
||||
/// CurrentFrame - The user can traverse the stack frame with the
|
||||
/// up/down/frame family of commands. This index indicates the current
|
||||
/// stack frame.
|
||||
unsigned CurrentFrame;
|
||||
|
||||
public:
|
||||
RuntimeInfo(ProgramInfo *PI, const InferiorProcess &ip)
|
||||
: ProgInfo(PI), IP(ip), CurrentFrame(0) {
|
||||
// Make sure that the top of stack has been materialized. If this throws
|
||||
// an exception, something is seriously wrong and the RuntimeInfo object
|
||||
// would be unusable anyway.
|
||||
getStackFrame(0);
|
||||
}
|
||||
|
||||
ProgramInfo &getProgramInfo() { return *ProgInfo; }
|
||||
const InferiorProcess &getInferiorProcess() const { return IP; }
|
||||
|
||||
//===------------------------------------------------------------------===//
|
||||
// Methods for inspecting the call stack of the program.
|
||||
//
|
||||
|
||||
/// getStackFrame - Materialize the specified stack frame and return it. If
|
||||
/// the specified ID is off of the bottom of the stack, throw an exception
|
||||
/// indicating the problem.
|
||||
StackFrame &getStackFrame(unsigned ID) {
|
||||
if (ID >= CallStack.size())
|
||||
materializeFrame(ID);
|
||||
return CallStack[ID];
|
||||
}
|
||||
|
||||
/// getCurrentFrame - Return the current stack frame object that the user is
|
||||
/// inspecting.
|
||||
StackFrame &getCurrentFrame() {
|
||||
assert(CallStack.size() > CurrentFrame &&
|
||||
"Must have materialized frame before making it current!");
|
||||
return CallStack[CurrentFrame];
|
||||
}
|
||||
|
||||
/// getCurrentFrameIdx - Return the current frame the user is inspecting.
|
||||
///
|
||||
unsigned getCurrentFrameIdx() const { return CurrentFrame; }
|
||||
|
||||
/// setCurrentFrameIdx - Set the current frame index to the specified value.
|
||||
/// Note that the specified frame must have been materialized with
|
||||
/// getStackFrame before it can be made current.
|
||||
void setCurrentFrameIdx(unsigned Idx) {
|
||||
assert(Idx < CallStack.size() &&
|
||||
"Must materialize frame before making it current!");
|
||||
CurrentFrame = Idx;
|
||||
}
|
||||
private:
|
||||
/// materializeFrame - Create and process all frames up to and including the
|
||||
/// specified frame number. This throws an exception if the specified frame
|
||||
/// ID is nonexistant.
|
||||
void materializeFrame(unsigned ID);
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
@ -1,87 +0,0 @@
|
||||
//===- SourceFile.h - Class to represent a source code file -----*- C++ -*-===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This file defines the SourceFile class which is used to represent a single
|
||||
// file of source code in the program, caching data from the file to make access
|
||||
// efficient.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef LLVM_DEBUGGER_SOURCEFILE_H
|
||||
#define LLVM_DEBUGGER_SOURCEFILE_H
|
||||
|
||||
#include "llvm/System/Path.h"
|
||||
#include "llvm/ADT/OwningPtr.h"
|
||||
#include <vector>
|
||||
|
||||
namespace llvm {
|
||||
class GlobalVariable;
|
||||
class MemoryBuffer;
|
||||
|
||||
class SourceFile {
|
||||
/// Filename - This is the full path of the file that is loaded.
|
||||
///
|
||||
sys::Path Filename;
|
||||
|
||||
/// Descriptor - The debugging descriptor for this source file. If there
|
||||
/// are multiple descriptors for the same file, this is just the first one
|
||||
/// encountered.
|
||||
///
|
||||
const GlobalVariable *Descriptor;
|
||||
|
||||
/// This is the memory mapping for the file so we can gain access to it.
|
||||
OwningPtr<MemoryBuffer> File;
|
||||
|
||||
/// LineOffset - This vector contains a mapping from source line numbers to
|
||||
/// their offsets in the file. This data is computed lazily, the first time
|
||||
/// it is asked for. If there are zero elements allocated in this vector,
|
||||
/// then it has not yet been computed.
|
||||
mutable std::vector<unsigned> LineOffset;
|
||||
|
||||
public:
|
||||
/// SourceFile constructor - Read in the specified source file if it exists,
|
||||
/// but do not build the LineOffsets table until it is requested. This will
|
||||
/// NOT throw an exception if the file is not found, if there is an error
|
||||
/// reading it, or if the user cancels the operation. Instead, it will just
|
||||
/// be an empty source file.
|
||||
SourceFile(const std::string &fn, const GlobalVariable *Desc);
|
||||
|
||||
~SourceFile();
|
||||
|
||||
/// getDescriptor - Return the debugging decriptor for this source file.
|
||||
///
|
||||
const GlobalVariable *getDescriptor() const { return Descriptor; }
|
||||
|
||||
/// getFilename - Return the fully resolved path that this file was loaded
|
||||
/// from.
|
||||
const std::string &getFilename() const { return Filename.str(); }
|
||||
|
||||
/// getSourceLine - Given a line number, return the start and end of the
|
||||
/// line in the file. If the line number is invalid, or if the file could
|
||||
/// not be loaded, null pointers are returned for the start and end of the
|
||||
/// file. Note that line numbers start with 0, not 1. This also strips off
|
||||
/// any newlines from the end of the line, to ease formatting of the text.
|
||||
void getSourceLine(unsigned LineNo, const char *&LineStart,
|
||||
const char *&LineEnd) const;
|
||||
|
||||
/// getNumLines - Return the number of lines the source file contains.
|
||||
///
|
||||
unsigned getNumLines() const {
|
||||
if (LineOffset.empty()) calculateLineOffsets();
|
||||
return static_cast<unsigned>(LineOffset.size());
|
||||
}
|
||||
|
||||
private:
|
||||
/// calculateLineOffsets - Compute the LineOffset vector for the current
|
||||
/// file.
|
||||
void calculateLineOffsets() const;
|
||||
};
|
||||
} // end namespace llvm
|
||||
|
||||
#endif
|
@ -1,99 +0,0 @@
|
||||
//===- SourceLanguage.h - Interact with source languages --------*- C++ -*-===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This file defines the abstract SourceLanguage interface, which is used by the
|
||||
// LLVM debugger to parse source-language expressions and render program objects
|
||||
// into a human readable string. In general, these classes perform all of the
|
||||
// analysis and interpretation of the language-specific debugger information.
|
||||
//
|
||||
// This interface is designed to be completely stateless, so all methods are
|
||||
// const.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef LLVM_DEBUGGER_SOURCELANGUAGE_H
|
||||
#define LLVM_DEBUGGER_SOURCELANGUAGE_H
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace llvm {
|
||||
class GlobalVariable;
|
||||
class SourceFileInfo;
|
||||
class SourceFunctionInfo;
|
||||
class ProgramInfo;
|
||||
class RuntimeInfo;
|
||||
|
||||
struct SourceLanguage {
|
||||
virtual ~SourceLanguage() {}
|
||||
|
||||
/// getSourceLanguageName - This method is used to implement the 'show
|
||||
/// language' command in the debugger.
|
||||
virtual const char *getSourceLanguageName() const = 0;
|
||||
|
||||
//===------------------------------------------------------------------===//
|
||||
// Methods used to implement debugger hooks.
|
||||
//
|
||||
|
||||
/// printInfo - Implementing this method allows the debugger to use
|
||||
/// language-specific 'info' extensions, e.g., 'info selectors' for objc.
|
||||
/// This method should return true if the specified string is recognized.
|
||||
///
|
||||
virtual bool printInfo(const std::string &What) const {
|
||||
return false;
|
||||
}
|
||||
|
||||
/// lookupFunction - Given a textual function name, return the
|
||||
/// SourceFunctionInfo descriptor for that function, or null if it cannot be
|
||||
/// found. If the program is currently running, the RuntimeInfo object
|
||||
/// provides information about the current evaluation context, otherwise it
|
||||
/// will be null.
|
||||
///
|
||||
virtual SourceFunctionInfo *lookupFunction(const std::string &FunctionName,
|
||||
ProgramInfo &PI,
|
||||
RuntimeInfo *RI = 0) const {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
//===------------------------------------------------------------------===//
|
||||
// Methods used to parse various pieces of program information.
|
||||
//
|
||||
|
||||
/// createSourceFileInfo - This method can be implemented by the front-end
|
||||
/// if it needs to keep track of information beyond what the debugger
|
||||
/// requires.
|
||||
virtual SourceFileInfo *
|
||||
createSourceFileInfo(const GlobalVariable *Desc, ProgramInfo &PI) const;
|
||||
|
||||
/// createSourceFunctionInfo - This method can be implemented by the derived
|
||||
/// SourceLanguage if it needs to keep track of more information than the
|
||||
/// SourceFunctionInfo has.
|
||||
virtual SourceFunctionInfo *
|
||||
createSourceFunctionInfo(const GlobalVariable *Desc, ProgramInfo &PI) const;
|
||||
|
||||
|
||||
//===------------------------------------------------------------------===//
|
||||
// Static methods used to get instances of various source languages.
|
||||
//
|
||||
|
||||
/// get - This method returns a source-language instance for the specified
|
||||
/// Dwarf 3 language identifier. If the language is unknown, an object is
|
||||
/// returned that can support some minimal operations, but is not terribly
|
||||
/// bright.
|
||||
static const SourceLanguage &get(unsigned ID);
|
||||
|
||||
/// get*Instance() - These methods return specific instances of languages.
|
||||
///
|
||||
static const SourceLanguage &getCFamilyInstance();
|
||||
static const SourceLanguage &getCPlusPlusInstance();
|
||||
static const SourceLanguage &getUnknownLanguageInstance();
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
@ -1,10 +0,0 @@
|
||||
add_llvm_library(LLVMDebugger
|
||||
Debugger.cpp
|
||||
ProgramInfo.cpp
|
||||
RuntimeInfo.cpp
|
||||
SourceFile.cpp
|
||||
SourceLanguage-CFamily.cpp
|
||||
SourceLanguage-CPlusPlus.cpp
|
||||
SourceLanguage-Unknown.cpp
|
||||
SourceLanguage.cpp
|
||||
)
|
@ -1,231 +0,0 @@
|
||||
//===-- Debugger.cpp - LLVM debugger library implementation ---------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This file contains the main implementation of the LLVM debugger library.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "llvm/Debugger/Debugger.h"
|
||||
#include "llvm/Module.h"
|
||||
#include "llvm/ModuleProvider.h"
|
||||
#include "llvm/Bitcode/ReaderWriter.h"
|
||||
#include "llvm/Debugger/InferiorProcess.h"
|
||||
#include "llvm/Support/MemoryBuffer.h"
|
||||
#include "llvm/ADT/StringExtras.h"
|
||||
#include <cstdlib>
|
||||
#include <memory>
|
||||
using namespace llvm;
|
||||
|
||||
/// Debugger constructor - Initialize the debugger to its initial, empty, state.
|
||||
///
|
||||
Debugger::Debugger() : Environment(0), Program(0), Process(0) {
|
||||
}
|
||||
|
||||
Debugger::~Debugger() {
|
||||
// Killing the program could throw an exception. We don't want to progagate
|
||||
// the exception out of our destructor though.
|
||||
try {
|
||||
killProgram();
|
||||
} catch (const char *) {
|
||||
} catch (const std::string &) {
|
||||
}
|
||||
|
||||
unloadProgram();
|
||||
}
|
||||
|
||||
/// getProgramPath - Get the path of the currently loaded program, or an
|
||||
/// empty string if none is loaded.
|
||||
std::string Debugger::getProgramPath() const {
|
||||
return Program ? Program->getModuleIdentifier() : "";
|
||||
}
|
||||
|
||||
static Module *
|
||||
getMaterializedModuleProvider(const std::string &Filename,
|
||||
LLVMContext& C) {
|
||||
std::auto_ptr<MemoryBuffer> Buffer;
|
||||
Buffer.reset(MemoryBuffer::getFileOrSTDIN(Filename.c_str()));
|
||||
if (Buffer.get())
|
||||
return ParseBitcodeFile(Buffer.get(), C);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/// loadProgram - If a program is currently loaded, unload it. Then search
|
||||
/// the PATH for the specified program, loading it when found. If the
|
||||
/// specified program cannot be found, an exception is thrown to indicate the
|
||||
/// error.
|
||||
void Debugger::loadProgram(const std::string &Filename, LLVMContext& C) {
|
||||
if ((Program = getMaterializedModuleProvider(Filename, C)) ||
|
||||
(Program = getMaterializedModuleProvider(Filename+".bc", C)))
|
||||
return; // Successfully loaded the program.
|
||||
|
||||
// Search the program path for the file...
|
||||
if (const char *PathS = getenv("PATH")) {
|
||||
std::string Path = PathS;
|
||||
|
||||
std::string Directory = getToken(Path, ":");
|
||||
while (!Directory.empty()) {
|
||||
if ((Program = getMaterializedModuleProvider(Directory +"/"+ Filename, C))
|
||||
|| (Program = getMaterializedModuleProvider(Directory +"/"+ Filename
|
||||
+ ".bc", C)))
|
||||
return; // Successfully loaded the program.
|
||||
|
||||
Directory = getToken(Path, ":");
|
||||
}
|
||||
}
|
||||
|
||||
throw "Could not find program '" + Filename + "'!";
|
||||
}
|
||||
|
||||
/// unloadProgram - If a program is running, kill it, then unload all traces
|
||||
/// of the current program. If no program is loaded, this method silently
|
||||
/// succeeds.
|
||||
void Debugger::unloadProgram() {
|
||||
if (!isProgramLoaded()) return;
|
||||
killProgram();
|
||||
delete Program;
|
||||
Program = 0;
|
||||
}
|
||||
|
||||
|
||||
/// createProgram - Create an instance of the currently loaded program,
|
||||
/// killing off any existing one. This creates the program and stops it at
|
||||
/// the first possible moment. If there is no program loaded or if there is a
|
||||
/// problem starting the program, this method throws an exception.
|
||||
void Debugger::createProgram() {
|
||||
if (!isProgramLoaded())
|
||||
throw "Cannot start program: none is loaded.";
|
||||
|
||||
// Kill any existing program.
|
||||
killProgram();
|
||||
|
||||
// Add argv[0] to the arguments vector..
|
||||
std::vector<std::string> Args(ProgramArguments);
|
||||
Args.insert(Args.begin(), getProgramPath());
|
||||
|
||||
// Start the new program... this could throw if the program cannot be started.
|
||||
Process = InferiorProcess::create(Program, Args, Environment);
|
||||
}
|
||||
|
||||
InferiorProcess *
|
||||
InferiorProcess::create(Module *M, const std::vector<std::string> &Arguments,
|
||||
const char * const *envp) {
|
||||
throw"No supported binding to inferior processes (debugger not implemented).";
|
||||
}
|
||||
|
||||
/// killProgram - If the program is currently executing, kill off the
|
||||
/// process and free up any state related to the currently running program. If
|
||||
/// there is no program currently running, this just silently succeeds.
|
||||
void Debugger::killProgram() {
|
||||
// The destructor takes care of the dirty work.
|
||||
try {
|
||||
delete Process;
|
||||
} catch (...) {
|
||||
Process = 0;
|
||||
throw;
|
||||
}
|
||||
Process = 0;
|
||||
}
|
||||
|
||||
/// stepProgram - Implement the 'step' command, continuing execution until
|
||||
/// the next possible stop point.
|
||||
void Debugger::stepProgram() {
|
||||
assert(isProgramRunning() && "Cannot step if the program isn't running!");
|
||||
try {
|
||||
Process->stepProgram();
|
||||
} catch (InferiorProcessDead &IPD) {
|
||||
killProgram();
|
||||
throw NonErrorException("The program stopped with exit code " +
|
||||
itostr(IPD.getExitCode()));
|
||||
} catch (...) {
|
||||
killProgram();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
/// nextProgram - Implement the 'next' command, continuing execution until
|
||||
/// the next possible stop point that is in the current function.
|
||||
void Debugger::nextProgram() {
|
||||
assert(isProgramRunning() && "Cannot next if the program isn't running!");
|
||||
try {
|
||||
// This should step the process. If the process enters a function, then it
|
||||
// should 'finish' it. However, figuring this out is tricky. In
|
||||
// particular, the program can do any of:
|
||||
// 0. Not change current frame.
|
||||
// 1. Entering or exiting a region within the current function
|
||||
// (which changes the frame ID, but which we shouldn't 'finish')
|
||||
// 2. Exiting the current function (which changes the frame ID)
|
||||
// 3. Entering a function (which should be 'finish'ed)
|
||||
// For this reason, we have to be very careful about when we decide to do
|
||||
// the 'finish'.
|
||||
|
||||
// Get the current frame, but don't trust it. It could change...
|
||||
void *CurrentFrame = Process->getPreviousFrame(0);
|
||||
|
||||
// Don't trust the current frame: get the caller frame.
|
||||
void *ParentFrame = Process->getPreviousFrame(CurrentFrame);
|
||||
|
||||
// Ok, we have some information, run the program one step.
|
||||
Process->stepProgram();
|
||||
|
||||
// Where is the new frame? The most common case, by far is that it has not
|
||||
// been modified (Case #0), in which case we don't need to do anything more.
|
||||
void *NewFrame = Process->getPreviousFrame(0);
|
||||
if (NewFrame != CurrentFrame) {
|
||||
// Ok, the frame changed. If we are case #1, then the parent frame will
|
||||
// be identical.
|
||||
void *NewParentFrame = Process->getPreviousFrame(NewFrame);
|
||||
if (ParentFrame != NewParentFrame) {
|
||||
// Ok, now we know we aren't case #0 or #1. Check to see if we entered
|
||||
// a new function. If so, the parent frame will be "CurrentFrame".
|
||||
if (CurrentFrame == NewParentFrame)
|
||||
Process->finishProgram(NewFrame);
|
||||
}
|
||||
}
|
||||
|
||||
} catch (InferiorProcessDead &IPD) {
|
||||
killProgram();
|
||||
throw NonErrorException("The program stopped with exit code " +
|
||||
itostr(IPD.getExitCode()));
|
||||
} catch (...) {
|
||||
killProgram();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
/// finishProgram - Implement the 'finish' command, continuing execution
|
||||
/// until the specified frame ID returns.
|
||||
void Debugger::finishProgram(void *Frame) {
|
||||
assert(isProgramRunning() && "Cannot cont if the program isn't running!");
|
||||
try {
|
||||
Process->finishProgram(Frame);
|
||||
} catch (InferiorProcessDead &IPD) {
|
||||
killProgram();
|
||||
throw NonErrorException("The program stopped with exit code " +
|
||||
itostr(IPD.getExitCode()));
|
||||
} catch (...) {
|
||||
killProgram();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
/// contProgram - Implement the 'cont' command, continuing execution until
|
||||
/// the next breakpoint is encountered.
|
||||
void Debugger::contProgram() {
|
||||
assert(isProgramRunning() && "Cannot cont if the program isn't running!");
|
||||
try {
|
||||
Process->contProgram();
|
||||
} catch (InferiorProcessDead &IPD) {
|
||||
killProgram();
|
||||
throw NonErrorException("The program stopped with exit code " +
|
||||
itostr(IPD.getExitCode()));
|
||||
} catch (...) {
|
||||
killProgram();
|
||||
throw;
|
||||
}
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
##===- lib/Debugger/Makefile -------------------------------*- Makefile -*-===##
|
||||
#
|
||||
# The LLVM Compiler Infrastructure
|
||||
#
|
||||
# This file is distributed under the University of Illinois Open Source
|
||||
# License. See LICENSE.TXT for details.
|
||||
#
|
||||
##===----------------------------------------------------------------------===##
|
||||
|
||||
LEVEL = ../..
|
||||
LIBRARYNAME = LLVMDebugger
|
||||
EXTRA_DIST = README.txt
|
||||
REQUIRES_EH := 1
|
||||
BUILD_ARCHIVE = 1
|
||||
|
||||
include $(LEVEL)/Makefile.common
|
@ -1,376 +0,0 @@
|
||||
//===-- ProgramInfo.cpp - Compute and cache info about a program ----------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This file implements the ProgramInfo and related classes, by sorting through
|
||||
// the loaded Module.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "llvm/Debugger/ProgramInfo.h"
|
||||
#include "llvm/Constants.h"
|
||||
#include "llvm/Analysis/ValueTracking.h"
|
||||
#include "llvm/DerivedTypes.h"
|
||||
#include "llvm/Intrinsics.h"
|
||||
#include "llvm/IntrinsicInst.h"
|
||||
#include "llvm/Instructions.h"
|
||||
#include "llvm/Module.h"
|
||||
#include "llvm/Debugger/SourceFile.h"
|
||||
#include "llvm/Debugger/SourceLanguage.h"
|
||||
#include "llvm/Support/raw_ostream.h"
|
||||
#include "llvm/Support/SlowOperationInformer.h"
|
||||
#include "llvm/ADT/STLExtras.h"
|
||||
using namespace llvm;
|
||||
|
||||
/// getGlobalVariablesUsing - Return all of the global variables which have the
|
||||
/// specified value in their initializer somewhere.
|
||||
static void getGlobalVariablesUsing(Value *V,
|
||||
std::vector<GlobalVariable*> &Found) {
|
||||
for (Value::use_iterator I = V->use_begin(), E = V->use_end(); I != E; ++I) {
|
||||
if (GlobalVariable *GV = dyn_cast<GlobalVariable>(*I))
|
||||
Found.push_back(GV);
|
||||
else if (Constant *C = dyn_cast<Constant>(*I))
|
||||
getGlobalVariablesUsing(C, Found);
|
||||
}
|
||||
}
|
||||
|
||||
/// getNextStopPoint - Follow the def-use chains of the specified LLVM value,
|
||||
/// traversing the use chains until we get to a stoppoint. When we do, return
|
||||
/// the source location of the stoppoint. If we don't find a stoppoint, return
|
||||
/// null.
|
||||
static const GlobalVariable *getNextStopPoint(const Value *V, unsigned &LineNo,
|
||||
unsigned &ColNo) {
|
||||
// The use-def chains can fork. As such, we pick the lowest numbered one we
|
||||
// find.
|
||||
const GlobalVariable *LastDesc = 0;
|
||||
unsigned LastLineNo = ~0;
|
||||
unsigned LastColNo = ~0;
|
||||
|
||||
for (Value::use_const_iterator UI = V->use_begin(), E = V->use_end();
|
||||
UI != E; ++UI) {
|
||||
bool ShouldRecurse = true;
|
||||
if (cast<Instruction>(*UI)->getOpcode() == Instruction::PHI) {
|
||||
// Infinite loops == bad, ignore PHI nodes.
|
||||
ShouldRecurse = false;
|
||||
} else if (const CallInst *CI = dyn_cast<CallInst>(*UI)) {
|
||||
|
||||
// If we found a stop point, check to see if it is earlier than what we
|
||||
// already have. If so, remember it.
|
||||
if (CI->getCalledFunction())
|
||||
if (const DbgStopPointInst *SPI = dyn_cast<DbgStopPointInst>(CI)) {
|
||||
unsigned CurLineNo = SPI->getLine();
|
||||
unsigned CurColNo = SPI->getColumn();
|
||||
const GlobalVariable *CurDesc = 0;
|
||||
const Value *Op = SPI->getContext();
|
||||
|
||||
if ((CurDesc = dyn_cast<GlobalVariable>(Op)) &&
|
||||
(LineNo < LastLineNo ||
|
||||
(LineNo == LastLineNo && ColNo < LastColNo))) {
|
||||
LastDesc = CurDesc;
|
||||
LastLineNo = CurLineNo;
|
||||
LastColNo = CurColNo;
|
||||
}
|
||||
ShouldRecurse = false;
|
||||
}
|
||||
}
|
||||
|
||||
// If this is not a phi node or a stopping point, recursively scan the users
|
||||
// of this instruction to skip over region.begin's and the like.
|
||||
if (ShouldRecurse) {
|
||||
unsigned CurLineNo, CurColNo;
|
||||
if (const GlobalVariable *GV = getNextStopPoint(*UI, CurLineNo,CurColNo)){
|
||||
if (LineNo < LastLineNo || (LineNo == LastLineNo && ColNo < LastColNo)){
|
||||
LastDesc = GV;
|
||||
LastLineNo = CurLineNo;
|
||||
LastColNo = CurColNo;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (LastDesc) {
|
||||
LineNo = LastLineNo != ~0U ? LastLineNo : 0;
|
||||
ColNo = LastColNo != ~0U ? LastColNo : 0;
|
||||
}
|
||||
return LastDesc;
|
||||
}
|
||||
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// SourceFileInfo implementation
|
||||
//
|
||||
|
||||
SourceFileInfo::SourceFileInfo(const GlobalVariable *Desc,
|
||||
const SourceLanguage &Lang)
|
||||
: Language(&Lang), Descriptor(Desc) {
|
||||
Version = 0;
|
||||
SourceText = 0;
|
||||
|
||||
if (Desc && Desc->hasInitializer())
|
||||
if (ConstantStruct *CS = dyn_cast<ConstantStruct>(Desc->getInitializer()))
|
||||
if (CS->getNumOperands() > 4) {
|
||||
if (ConstantInt *CUI = dyn_cast<ConstantInt>(CS->getOperand(1)))
|
||||
Version = CUI->getZExtValue();
|
||||
|
||||
if (!GetConstantStringInfo(CS->getOperand(3), BaseName))
|
||||
BaseName = "";
|
||||
if (!GetConstantStringInfo(CS->getOperand(4), Directory))
|
||||
Directory = "";
|
||||
}
|
||||
}
|
||||
|
||||
SourceFileInfo::~SourceFileInfo() {
|
||||
delete SourceText;
|
||||
}
|
||||
|
||||
SourceFile &SourceFileInfo::getSourceText() const {
|
||||
// FIXME: this should take into account the source search directories!
|
||||
if (SourceText == 0) { // Read the file in if we haven't already.
|
||||
sys::Path tmpPath;
|
||||
if (!Directory.empty())
|
||||
tmpPath.set(Directory);
|
||||
tmpPath.appendComponent(BaseName);
|
||||
if (tmpPath.canRead())
|
||||
SourceText = new SourceFile(tmpPath.str(), Descriptor);
|
||||
else
|
||||
SourceText = new SourceFile(BaseName, Descriptor);
|
||||
}
|
||||
return *SourceText;
|
||||
}
|
||||
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// SourceFunctionInfo implementation
|
||||
//
|
||||
SourceFunctionInfo::SourceFunctionInfo(ProgramInfo &PI,
|
||||
const GlobalVariable *Desc)
|
||||
: Descriptor(Desc) {
|
||||
LineNo = ColNo = 0;
|
||||
if (Desc && Desc->hasInitializer())
|
||||
if (ConstantStruct *CS = dyn_cast<ConstantStruct>(Desc->getInitializer()))
|
||||
if (CS->getNumOperands() > 2) {
|
||||
// Entry #1 is the file descriptor.
|
||||
if (const GlobalVariable *GV =
|
||||
dyn_cast<GlobalVariable>(CS->getOperand(1)))
|
||||
SourceFile = &PI.getSourceFile(GV);
|
||||
|
||||
// Entry #2 is the function name.
|
||||
if (!GetConstantStringInfo(CS->getOperand(2), Name))
|
||||
Name = "";
|
||||
}
|
||||
}
|
||||
|
||||
/// getSourceLocation - This method returns the location of the first stopping
|
||||
/// point in the function.
|
||||
void SourceFunctionInfo::getSourceLocation(unsigned &RetLineNo,
|
||||
unsigned &RetColNo) const {
|
||||
// If we haven't computed this yet...
|
||||
if (!LineNo) {
|
||||
// Look at all of the users of the function descriptor, looking for calls to
|
||||
// %llvm.dbg.func.start.
|
||||
for (Value::use_const_iterator UI = Descriptor->use_begin(),
|
||||
E = Descriptor->use_end(); UI != E; ++UI)
|
||||
if (const CallInst *CI = dyn_cast<CallInst>(*UI))
|
||||
if (const Function *F = CI->getCalledFunction())
|
||||
if (F->getIntrinsicID() == Intrinsic::dbg_func_start) {
|
||||
// We found the start of the function. Check to see if there are
|
||||
// any stop points on the use-list of the function start.
|
||||
const GlobalVariable *SD = getNextStopPoint(CI, LineNo, ColNo);
|
||||
if (SD) { // We found the first stop point!
|
||||
// This is just a sanity check.
|
||||
if (getSourceFile().getDescriptor() != SD)
|
||||
outs() << "WARNING: first line of function is not in the"
|
||||
<< " file that the function descriptor claims it is in.\n";
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
RetLineNo = LineNo; RetColNo = ColNo;
|
||||
}
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// ProgramInfo implementation
|
||||
//
|
||||
|
||||
ProgramInfo::ProgramInfo(Module *m) : M(m), ProgramTimeStamp(0,0) {
|
||||
assert(M && "Cannot create program information with a null module!");
|
||||
sys::PathWithStatus ModPath(M->getModuleIdentifier());
|
||||
const sys::FileStatus *Stat = ModPath.getFileStatus();
|
||||
if (Stat)
|
||||
ProgramTimeStamp = Stat->getTimestamp();
|
||||
|
||||
SourceFilesIsComplete = false;
|
||||
SourceFunctionsIsComplete = false;
|
||||
}
|
||||
|
||||
ProgramInfo::~ProgramInfo() {
|
||||
// Delete cached information about source program objects...
|
||||
for (std::map<const GlobalVariable*, SourceFileInfo*>::iterator
|
||||
I = SourceFiles.begin(), E = SourceFiles.end(); I != E; ++I)
|
||||
delete I->second;
|
||||
for (std::map<const GlobalVariable*, SourceFunctionInfo*>::iterator
|
||||
I = SourceFunctions.begin(), E = SourceFunctions.end(); I != E; ++I)
|
||||
delete I->second;
|
||||
|
||||
// Delete the source language caches.
|
||||
for (unsigned i = 0, e = LanguageCaches.size(); i != e; ++i)
|
||||
delete LanguageCaches[i].second;
|
||||
}
|
||||
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// SourceFileInfo tracking...
|
||||
//
|
||||
|
||||
/// getSourceFile - Return source file information for the specified source file
|
||||
/// descriptor object, adding it to the collection as needed. This method
|
||||
/// always succeeds (is unambiguous), and is always efficient.
|
||||
///
|
||||
const SourceFileInfo &
|
||||
ProgramInfo::getSourceFile(const GlobalVariable *Desc) {
|
||||
SourceFileInfo *&Result = SourceFiles[Desc];
|
||||
if (Result) return *Result;
|
||||
|
||||
// Figure out what language this source file comes from...
|
||||
unsigned LangID = 0; // Zero is unknown language
|
||||
if (Desc && Desc->hasInitializer())
|
||||
if (ConstantStruct *CS = dyn_cast<ConstantStruct>(Desc->getInitializer()))
|
||||
if (CS->getNumOperands() > 2)
|
||||
if (ConstantInt *CUI = dyn_cast<ConstantInt>(CS->getOperand(2)))
|
||||
LangID = CUI->getZExtValue();
|
||||
|
||||
const SourceLanguage &Lang = SourceLanguage::get(LangID);
|
||||
SourceFileInfo *New = Lang.createSourceFileInfo(Desc, *this);
|
||||
|
||||
// FIXME: this should check to see if there is already a Filename/WorkingDir
|
||||
// pair that matches this one. If so, we shouldn't create the duplicate!
|
||||
//
|
||||
SourceFileIndex.insert(std::make_pair(New->getBaseName(), New));
|
||||
return *(Result = New);
|
||||
}
|
||||
|
||||
|
||||
/// getSourceFiles - Index all of the source files in the program and return
|
||||
/// a mapping of it. This information is lazily computed the first time
|
||||
/// that it is requested. Since this information can take a long time to
|
||||
/// compute, the user is given a chance to cancel it. If this occurs, an
|
||||
/// exception is thrown.
|
||||
const std::map<const GlobalVariable*, SourceFileInfo*> &
|
||||
ProgramInfo::getSourceFiles(bool RequiresCompleteMap) {
|
||||
// If we have a fully populated map, or if the client doesn't need one, just
|
||||
// return what we have.
|
||||
if (SourceFilesIsComplete || !RequiresCompleteMap)
|
||||
return SourceFiles;
|
||||
|
||||
// Ok, all of the source file descriptors (compile_unit in dwarf terms),
|
||||
// should be on the use list of the llvm.dbg.translation_units global.
|
||||
//
|
||||
GlobalVariable *Units =
|
||||
M->getGlobalVariable("llvm.dbg.translation_units",
|
||||
StructType::get(M->getContext()));
|
||||
if (Units == 0)
|
||||
throw "Program contains no debugging information!";
|
||||
|
||||
std::vector<GlobalVariable*> TranslationUnits;
|
||||
getGlobalVariablesUsing(Units, TranslationUnits);
|
||||
|
||||
SlowOperationInformer SOI("building source files index");
|
||||
|
||||
// Loop over all of the translation units found, building the SourceFiles
|
||||
// mapping.
|
||||
for (unsigned i = 0, e = TranslationUnits.size(); i != e; ++i) {
|
||||
getSourceFile(TranslationUnits[i]);
|
||||
if (SOI.progress(i+1, e))
|
||||
throw "While building source files index, operation cancelled.";
|
||||
}
|
||||
|
||||
// Ok, if we got this far, then we indexed the whole program.
|
||||
SourceFilesIsComplete = true;
|
||||
return SourceFiles;
|
||||
}
|
||||
|
||||
/// getSourceFile - Look up the file with the specified name. If there is
|
||||
/// more than one match for the specified filename, prompt the user to pick
|
||||
/// one. If there is no source file that matches the specified name, throw
|
||||
/// an exception indicating that we can't find the file. Otherwise, return
|
||||
/// the file information for that file.
|
||||
const SourceFileInfo &ProgramInfo::getSourceFile(const std::string &Filename) {
|
||||
std::multimap<std::string, SourceFileInfo*>::const_iterator Start, End;
|
||||
getSourceFiles();
|
||||
tie(Start, End) = SourceFileIndex.equal_range(Filename);
|
||||
|
||||
if (Start == End) throw "Could not find source file '" + Filename + "'!";
|
||||
const SourceFileInfo &SFI = *Start->second;
|
||||
++Start;
|
||||
if (Start == End) return SFI;
|
||||
|
||||
throw "FIXME: Multiple source files with the same name not implemented!";
|
||||
}
|
||||
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// SourceFunctionInfo tracking...
|
||||
//
|
||||
|
||||
|
||||
/// getFunction - Return function information for the specified function
|
||||
/// descriptor object, adding it to the collection as needed. This method
|
||||
/// always succeeds (is unambiguous), and is always efficient.
|
||||
///
|
||||
const SourceFunctionInfo &
|
||||
ProgramInfo::getFunction(const GlobalVariable *Desc) {
|
||||
SourceFunctionInfo *&Result = SourceFunctions[Desc];
|
||||
if (Result) return *Result;
|
||||
|
||||
// Figure out what language this function comes from...
|
||||
const GlobalVariable *SourceFileDesc = 0;
|
||||
if (Desc && Desc->hasInitializer())
|
||||
if (ConstantStruct *CS = dyn_cast<ConstantStruct>(Desc->getInitializer()))
|
||||
if (CS->getNumOperands() > 0)
|
||||
if (const GlobalVariable *GV =
|
||||
dyn_cast<GlobalVariable>(CS->getOperand(1)))
|
||||
SourceFileDesc = GV;
|
||||
|
||||
const SourceLanguage &Lang = getSourceFile(SourceFileDesc).getLanguage();
|
||||
return *(Result = Lang.createSourceFunctionInfo(Desc, *this));
|
||||
}
|
||||
|
||||
|
||||
// getSourceFunctions - Index all of the functions in the program and return
|
||||
// them. This information is lazily computed the first time that it is
|
||||
// requested. Since this information can take a long time to compute, the user
|
||||
// is given a chance to cancel it. If this occurs, an exception is thrown.
|
||||
const std::map<const GlobalVariable*, SourceFunctionInfo*> &
|
||||
ProgramInfo::getSourceFunctions(bool RequiresCompleteMap) {
|
||||
if (SourceFunctionsIsComplete || !RequiresCompleteMap)
|
||||
return SourceFunctions;
|
||||
|
||||
// Ok, all of the source function descriptors (subprogram in dwarf terms),
|
||||
// should be on the use list of the llvm.dbg.translation_units global.
|
||||
//
|
||||
GlobalVariable *Units =
|
||||
M->getGlobalVariable("llvm.dbg.globals", StructType::get(M->getContext()));
|
||||
if (Units == 0)
|
||||
throw "Program contains no debugging information!";
|
||||
|
||||
std::vector<GlobalVariable*> Functions;
|
||||
getGlobalVariablesUsing(Units, Functions);
|
||||
|
||||
SlowOperationInformer SOI("building functions index");
|
||||
|
||||
// Loop over all of the functions found, building the SourceFunctions mapping.
|
||||
for (unsigned i = 0, e = Functions.size(); i != e; ++i) {
|
||||
getFunction(Functions[i]);
|
||||
if (SOI.progress(i+1, e))
|
||||
throw "While functions index, operation cancelled.";
|
||||
}
|
||||
|
||||
// Ok, if we got this far, then we indexed the whole program.
|
||||
SourceFunctionsIsComplete = true;
|
||||
return SourceFunctions;
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
//===-- llvm/lib/Debugger/ - LLVM Debugger interfaces ---------------------===//
|
||||
|
||||
This directory contains the implementation of the LLVM debugger backend. This
|
||||
directory builds into a library which can be used by various debugger
|
||||
front-ends to debug LLVM programs. The current command line LLVM debugger,
|
||||
llvm-db is currently the only client of this library, but others could be
|
||||
built, to provide a GUI front-end for example.
|
@ -1,69 +0,0 @@
|
||||
//===-- RuntimeInfo.cpp - Compute and cache info about running program ----===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This file implements the RuntimeInfo and related classes, by querying and
|
||||
// cachine information from the running inferior process.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "llvm/Debugger/InferiorProcess.h"
|
||||
#include "llvm/Debugger/ProgramInfo.h"
|
||||
#include "llvm/Debugger/RuntimeInfo.h"
|
||||
using namespace llvm;
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// StackFrame class implementation
|
||||
|
||||
StackFrame::StackFrame(RuntimeInfo &ri, void *ParentFrameID)
|
||||
: RI(ri), SourceInfo(0) {
|
||||
FrameID = RI.getInferiorProcess().getPreviousFrame(ParentFrameID);
|
||||
if (FrameID == 0) throw "Stack frame does not exist!";
|
||||
|
||||
// Compute lazily as needed.
|
||||
FunctionDesc = 0;
|
||||
}
|
||||
|
||||
const GlobalVariable *StackFrame::getFunctionDesc() {
|
||||
if (FunctionDesc == 0)
|
||||
FunctionDesc = RI.getInferiorProcess().getSubprogramDesc(FrameID);
|
||||
return FunctionDesc;
|
||||
}
|
||||
|
||||
/// getSourceLocation - Return the source location that this stack frame is
|
||||
/// sitting at.
|
||||
void StackFrame::getSourceLocation(unsigned &lineNo, unsigned &colNo,
|
||||
const SourceFileInfo *&sourceInfo) {
|
||||
if (SourceInfo == 0) {
|
||||
const GlobalVariable *SourceDesc = 0;
|
||||
RI.getInferiorProcess().getFrameLocation(FrameID, LineNo,ColNo, SourceDesc);
|
||||
SourceInfo = &RI.getProgramInfo().getSourceFile(SourceDesc);
|
||||
}
|
||||
|
||||
lineNo = LineNo;
|
||||
colNo = ColNo;
|
||||
sourceInfo = SourceInfo;
|
||||
}
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// RuntimeInfo class implementation
|
||||
|
||||
/// materializeFrame - Create and process all frames up to and including the
|
||||
/// specified frame number. This throws an exception if the specified frame
|
||||
/// ID is nonexistant.
|
||||
void RuntimeInfo::materializeFrame(unsigned ID) {
|
||||
assert(ID >= CallStack.size() && "no need to materialize this frame!");
|
||||
void *CurFrame = 0;
|
||||
if (!CallStack.empty())
|
||||
CurFrame = CallStack.back().getFrameID();
|
||||
|
||||
while (CallStack.size() <= ID) {
|
||||
CallStack.push_back(StackFrame(*this, CurFrame));
|
||||
CurFrame = CallStack.back().getFrameID();
|
||||
}
|
||||
}
|
@ -1,82 +0,0 @@
|
||||
//===-- SourceFile.cpp - SourceFile implementation for the debugger -------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This file implements the SourceFile class for the LLVM debugger.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "llvm/Debugger/SourceFile.h"
|
||||
#include "llvm/Support/MemoryBuffer.h"
|
||||
#include <cassert>
|
||||
using namespace llvm;
|
||||
|
||||
static const char EmptyFile = 0;
|
||||
|
||||
SourceFile::SourceFile(const std::string &fn, const GlobalVariable *Desc)
|
||||
: Filename(fn), Descriptor(Desc) {
|
||||
File.reset(MemoryBuffer::getFileOrSTDIN(fn));
|
||||
|
||||
// On error, return an empty buffer.
|
||||
if (File == 0)
|
||||
File.reset(MemoryBuffer::getMemBuffer(&EmptyFile, &EmptyFile));
|
||||
}
|
||||
|
||||
SourceFile::~SourceFile() {
|
||||
}
|
||||
|
||||
|
||||
/// calculateLineOffsets - Compute the LineOffset vector for the current file.
|
||||
///
|
||||
void SourceFile::calculateLineOffsets() const {
|
||||
assert(LineOffset.empty() && "Line offsets already computed!");
|
||||
const char *BufPtr = File->getBufferStart();
|
||||
const char *FileStart = BufPtr;
|
||||
const char *FileEnd = File->getBufferEnd();
|
||||
do {
|
||||
LineOffset.push_back(BufPtr-FileStart);
|
||||
|
||||
// Scan until we get to a newline.
|
||||
while (BufPtr != FileEnd && *BufPtr != '\n' && *BufPtr != '\r')
|
||||
++BufPtr;
|
||||
|
||||
if (BufPtr != FileEnd) {
|
||||
++BufPtr; // Skip over the \n or \r
|
||||
if (BufPtr[-1] == '\r' && BufPtr != FileEnd && BufPtr[0] == '\n')
|
||||
++BufPtr; // Skip over dos/windows style \r\n's
|
||||
}
|
||||
} while (BufPtr != FileEnd);
|
||||
}
|
||||
|
||||
|
||||
/// getSourceLine - Given a line number, return the start and end of the line
|
||||
/// in the file. If the line number is invalid, or if the file could not be
|
||||
/// loaded, null pointers are returned for the start and end of the file. Note
|
||||
/// that line numbers start with 0, not 1.
|
||||
void SourceFile::getSourceLine(unsigned LineNo, const char *&LineStart,
|
||||
const char *&LineEnd) const {
|
||||
LineStart = LineEnd = 0;
|
||||
if (LineOffset.empty()) calculateLineOffsets();
|
||||
|
||||
// Asking for an out-of-range line number?
|
||||
if (LineNo >= LineOffset.size()) return;
|
||||
|
||||
// Otherwise, they are asking for a valid line, which we can fulfill.
|
||||
LineStart = File->getBufferStart()+LineOffset[LineNo];
|
||||
|
||||
if (LineNo+1 < LineOffset.size())
|
||||
LineEnd = File->getBufferStart()+LineOffset[LineNo+1];
|
||||
else
|
||||
LineEnd = File->getBufferEnd();
|
||||
|
||||
// If the line ended with a newline, strip it off.
|
||||
while (LineEnd != LineStart && (LineEnd[-1] == '\n' || LineEnd[-1] == '\r'))
|
||||
--LineEnd;
|
||||
|
||||
assert(LineEnd >= LineStart && "We somehow got our pointers swizzled!");
|
||||
}
|
@ -1,28 +0,0 @@
|
||||
//===-- SourceLanguage-CFamily.cpp - C family SourceLanguage impl ---------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This file implements the SourceLanguage class for the C family of languages
|
||||
// (K&R C, C89, C99, etc).
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "llvm/Debugger/SourceLanguage.h"
|
||||
using namespace llvm;
|
||||
|
||||
#if 0
|
||||
namespace {
|
||||
struct CSL : public SourceLanguage {
|
||||
} TheCSourceLanguageInstance;
|
||||
}
|
||||
#endif
|
||||
|
||||
const SourceLanguage &SourceLanguage::getCFamilyInstance() {
|
||||
return get(0); // We don't have an implementation for C yet fall back on
|
||||
// generic
|
||||
}
|
@ -1,27 +0,0 @@
|
||||
//===-- SourceLanguage-CPlusPlus.cpp - C++ SourceLanguage impl ------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This file implements the SourceLanguage class for the C++ language.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "llvm/Debugger/SourceLanguage.h"
|
||||
using namespace llvm;
|
||||
|
||||
#if 0
|
||||
namespace {
|
||||
struct CPPSL : public SourceLanguage {
|
||||
} TheCPlusPlusLanguageInstance;
|
||||
}
|
||||
#endif
|
||||
|
||||
const SourceLanguage &SourceLanguage::getCPlusPlusInstance() {
|
||||
return get(0); // We don't have an implementation for C yet fall back on
|
||||
// generic
|
||||
}
|
@ -1,137 +0,0 @@
|
||||
//===-- SourceLanguage-Unknown.cpp - Implement itf for unknown languages --===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// If the LLVM debugger does not have a module for a particular language, it
|
||||
// falls back on using this one to perform the source-language interface. This
|
||||
// interface is not wonderful, but it gets the job done.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "llvm/Debugger/SourceLanguage.h"
|
||||
#include "llvm/Debugger/ProgramInfo.h"
|
||||
#include "llvm/Support/raw_ostream.h"
|
||||
#include <cassert>
|
||||
using namespace llvm;
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// Implement the SourceLanguage cache for the Unknown language.
|
||||
//
|
||||
|
||||
namespace {
|
||||
/// SLUCache - This cache allows for efficient lookup of source functions by
|
||||
/// name.
|
||||
///
|
||||
struct SLUCache : public SourceLanguageCache {
|
||||
ProgramInfo &PI;
|
||||
std::multimap<std::string, SourceFunctionInfo*> FunctionMap;
|
||||
public:
|
||||
SLUCache(ProgramInfo &pi);
|
||||
|
||||
typedef std::multimap<std::string, SourceFunctionInfo*>::const_iterator
|
||||
fm_iterator;
|
||||
|
||||
std::pair<fm_iterator, fm_iterator>
|
||||
getFunction(const std::string &Name) const {
|
||||
return FunctionMap.equal_range(Name);
|
||||
}
|
||||
|
||||
SourceFunctionInfo *addSourceFunction(SourceFunctionInfo *SF) {
|
||||
FunctionMap.insert(std::make_pair(SF->getSymbolicName(), SF));
|
||||
return SF;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
SLUCache::SLUCache(ProgramInfo &pi) : PI(pi) {
|
||||
}
|
||||
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// Implement SourceLanguageUnknown class, which is used to handle unrecognized
|
||||
// languages.
|
||||
//
|
||||
|
||||
namespace {
|
||||
static struct SLU : public SourceLanguage {
|
||||
//===------------------------------------------------------------------===//
|
||||
// Implement the miscellaneous methods...
|
||||
//
|
||||
virtual const char *getSourceLanguageName() const {
|
||||
return "unknown";
|
||||
}
|
||||
|
||||
/// lookupFunction - Given a textual function name, return the
|
||||
/// SourceFunctionInfo descriptor for that function, or null if it cannot be
|
||||
/// found. If the program is currently running, the RuntimeInfo object
|
||||
/// provides information about the current evaluation context, otherwise it
|
||||
/// will be null.
|
||||
///
|
||||
virtual SourceFunctionInfo *lookupFunction(const std::string &FunctionName,
|
||||
ProgramInfo &PI,
|
||||
RuntimeInfo *RI = 0) const;
|
||||
|
||||
//===------------------------------------------------------------------===//
|
||||
// We do use a cache for information...
|
||||
//
|
||||
typedef SLUCache CacheType;
|
||||
SLUCache *createSourceLanguageCache(ProgramInfo &PI) const {
|
||||
return new SLUCache(PI);
|
||||
}
|
||||
|
||||
/// createSourceFunctionInfo - Create the new object and inform the cache of
|
||||
/// the new function.
|
||||
virtual SourceFunctionInfo *
|
||||
createSourceFunctionInfo(const GlobalVariable *Desc, ProgramInfo &PI) const;
|
||||
|
||||
} TheUnknownSourceLanguageInstance;
|
||||
}
|
||||
|
||||
const SourceLanguage &SourceLanguage::getUnknownLanguageInstance() {
|
||||
return TheUnknownSourceLanguageInstance;
|
||||
}
|
||||
|
||||
|
||||
SourceFunctionInfo *
|
||||
SLU::createSourceFunctionInfo(const GlobalVariable *Desc,
|
||||
ProgramInfo &PI) const {
|
||||
SourceFunctionInfo *Result = new SourceFunctionInfo(PI, Desc);
|
||||
return PI.getLanguageCache(this).addSourceFunction(Result);
|
||||
}
|
||||
|
||||
|
||||
/// lookupFunction - Given a textual function name, return the
|
||||
/// SourceFunctionInfo descriptor for that function, or null if it cannot be
|
||||
/// found. If the program is currently running, the RuntimeInfo object
|
||||
/// provides information about the current evaluation context, otherwise it will
|
||||
/// be null.
|
||||
///
|
||||
SourceFunctionInfo *SLU::lookupFunction(const std::string &FunctionName,
|
||||
ProgramInfo &PI, RuntimeInfo *RI) const{
|
||||
SLUCache &Cache = PI.getLanguageCache(this);
|
||||
std::pair<SLUCache::fm_iterator, SLUCache::fm_iterator> IP
|
||||
= Cache.getFunction(FunctionName);
|
||||
|
||||
if (IP.first == IP.second) {
|
||||
if (PI.allSourceFunctionsRead())
|
||||
return 0; // Nothing found
|
||||
|
||||
// Otherwise, we might be able to find the function if we read all of them
|
||||
// in. Do so now.
|
||||
PI.getSourceFunctions();
|
||||
assert(PI.allSourceFunctionsRead() && "Didn't read in all functions?");
|
||||
return lookupFunction(FunctionName, PI, RI);
|
||||
}
|
||||
|
||||
SourceFunctionInfo *Found = IP.first->second;
|
||||
++IP.first;
|
||||
if (IP.first != IP.second)
|
||||
outs() << "Whoa, found multiple functions with the same name. I should"
|
||||
<< " ask the user which one to use: FIXME!\n";
|
||||
return Found;
|
||||
}
|
@ -1,54 +0,0 @@
|
||||
//===-- SourceLanguage.cpp - Implement the SourceLanguage class -----------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This file implements the SourceLanguage class.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "llvm/Debugger/SourceLanguage.h"
|
||||
#include "llvm/Debugger/ProgramInfo.h"
|
||||
using namespace llvm;
|
||||
|
||||
const SourceLanguage &SourceLanguage::get(unsigned ID) {
|
||||
switch (ID) {
|
||||
case 1: // DW_LANG_C89
|
||||
case 2: // DW_LANG_C
|
||||
case 12: // DW_LANG_C99
|
||||
return getCFamilyInstance();
|
||||
|
||||
case 4: // DW_LANG_C_plus_plus
|
||||
return getCPlusPlusInstance();
|
||||
|
||||
case 3: // DW_LANG_Ada83
|
||||
case 5: // DW_LANG_Cobol74
|
||||
case 6: // DW_LANG_Cobol85
|
||||
case 7: // DW_LANG_Fortran77
|
||||
case 8: // DW_LANG_Fortran90
|
||||
case 9: // DW_LANG_Pascal83
|
||||
case 10: // DW_LANG_Modula2
|
||||
case 11: // DW_LANG_Java
|
||||
case 13: // DW_LANG_Ada95
|
||||
case 14: // DW_LANG_Fortran95
|
||||
default:
|
||||
return getUnknownLanguageInstance();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
SourceFileInfo *
|
||||
SourceLanguage::createSourceFileInfo(const GlobalVariable *Desc,
|
||||
ProgramInfo &PI) const {
|
||||
return new SourceFileInfo(Desc, *this);
|
||||
}
|
||||
|
||||
SourceFunctionInfo *
|
||||
SourceLanguage::createSourceFunctionInfo(const GlobalVariable *Desc,
|
||||
ProgramInfo &PI) const {
|
||||
return new SourceFunctionInfo(PI, Desc);
|
||||
}
|
@ -11,7 +11,7 @@ LEVEL = ..
|
||||
include $(LEVEL)/Makefile.config
|
||||
|
||||
PARALLEL_DIRS := VMCore AsmParser Bitcode Archive Analysis Transforms CodeGen \
|
||||
Target ExecutionEngine Debugger Linker MC CompilerDriver
|
||||
Target ExecutionEngine Linker MC CompilerDriver
|
||||
|
||||
include $(LEVEL)/Makefile.common
|
||||
|
||||
|
@ -27,7 +27,6 @@ add_subdirectory(llvm-link)
|
||||
add_subdirectory(lli)
|
||||
|
||||
add_subdirectory(llvm-extract)
|
||||
add_subdirectory(llvm-db)
|
||||
|
||||
add_subdirectory(bugpoint)
|
||||
add_subdirectory(llvm-bcanalyzer)
|
||||
|
@ -19,7 +19,7 @@ DIRS := llvm-config
|
||||
PARALLEL_DIRS := opt llvm-as llvm-dis \
|
||||
llc llvm-ranlib llvm-ar llvm-nm \
|
||||
llvm-ld llvm-prof llvm-link \
|
||||
lli llvm-extract llvm-db \
|
||||
lli llvm-extract \
|
||||
bugpoint llvm-bcanalyzer llvm-stub \
|
||||
llvm-mc llvmc
|
||||
|
||||
|
@ -1,111 +0,0 @@
|
||||
//===- CLICommand.h - Classes used to represent commands --------*- C++ -*-===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This file defines a small class hierarchy used to represent the various types
|
||||
// of commands in the CLI debugger front-end.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef CLICOMMAND_H
|
||||
#define CLICOMMAND_H
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <cassert>
|
||||
|
||||
namespace llvm {
|
||||
class CLIDebugger;
|
||||
|
||||
/// CLICommand - Base class of the hierarchy, used to provide the abstract
|
||||
/// interface common to all commands.
|
||||
///
|
||||
class CLICommand {
|
||||
/// ShortHelp, LongHelp - The short and long helps strings printed for the
|
||||
/// command. The ShortHelp string should be a single line of text without a
|
||||
/// newline. The LongHelp string should be a full description with
|
||||
/// terminating newline.
|
||||
std::string ShortHelp, LongHelp;
|
||||
|
||||
/// RefCount - This contains the number of entries in the CLIDebugger
|
||||
/// CommandTable that points to this command.
|
||||
unsigned RefCount;
|
||||
|
||||
/// OptionNames - This contains a list of names for the option. Keeping
|
||||
/// track of this is done just to make the help output more helpful.
|
||||
///
|
||||
std::vector<std::string> OptionNames;
|
||||
public:
|
||||
CLICommand(const std::string &SH, const std::string &LH)
|
||||
: ShortHelp(SH), LongHelp(LH), RefCount(0) {}
|
||||
|
||||
virtual ~CLICommand() {}
|
||||
|
||||
/// addRef/dropRef - Implement a simple reference counting scheme to make
|
||||
/// sure we delete commands that are no longer used.
|
||||
void addRef() { ++RefCount; }
|
||||
void dropRef() {
|
||||
if (--RefCount == 0) delete this;
|
||||
}
|
||||
|
||||
/// getPrimaryOptionName - Return the first name the option was added under.
|
||||
/// This is the name we report for the option in the help output.
|
||||
std::string getPrimaryOptionName() const {
|
||||
return OptionNames.empty() ? "" : OptionNames[0];
|
||||
}
|
||||
|
||||
/// getOptionName - Return all of the names the option is registered as.
|
||||
///
|
||||
const std::vector<std::string> &getOptionNames() const {
|
||||
return OptionNames;
|
||||
}
|
||||
|
||||
/// addOptionName - Add a name that this option is known as.
|
||||
///
|
||||
void addOptionName(const std::string &Name) {
|
||||
OptionNames.push_back(Name);
|
||||
}
|
||||
|
||||
/// removeOptionName - Eliminate one of the names for this option.
|
||||
///
|
||||
void removeOptionName(const std::string &Name) {
|
||||
unsigned i = 0;
|
||||
for (; OptionNames[i] != Name; ++i)
|
||||
assert(i+1 < OptionNames.size() && "Didn't find option name!");
|
||||
OptionNames.erase(OptionNames.begin()+i);
|
||||
}
|
||||
|
||||
|
||||
/// getShortHelp - Return the short help string for this command.
|
||||
///
|
||||
const std::string &getShortHelp() { return ShortHelp; }
|
||||
|
||||
/// getLongHelp - Return the long help string for this command, if it
|
||||
/// exists.
|
||||
const std::string &getLongHelp() { return LongHelp; }
|
||||
|
||||
virtual void runCommand(CLIDebugger &D, std::string &Arguments) = 0;
|
||||
};
|
||||
|
||||
/// BuiltinCLICommand - This class represents commands that are built directly
|
||||
/// into the debugger.
|
||||
class BuiltinCLICommand : public CLICommand {
|
||||
// Impl - Pointer to the method that implements the command
|
||||
void (CLIDebugger::*Impl)(std::string&);
|
||||
public:
|
||||
BuiltinCLICommand(const std::string &ShortHelp, const std::string &LongHelp,
|
||||
void (CLIDebugger::*impl)(std::string&))
|
||||
: CLICommand(ShortHelp, LongHelp), Impl(impl) {}
|
||||
|
||||
void runCommand(CLIDebugger &D, std::string &Arguments) {
|
||||
(D.*Impl)(Arguments);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
@ -1,309 +0,0 @@
|
||||
//===-- CLIDebugger.cpp - Command Line Interface to the Debugger ----------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This file contains the main implementation of the Command Line Interface to
|
||||
// the debugger.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "CLIDebugger.h"
|
||||
#include "CLICommand.h"
|
||||
#include "llvm/Debugger/SourceFile.h"
|
||||
#include "llvm/ADT/StringExtras.h"
|
||||
#include <iostream>
|
||||
using namespace llvm;
|
||||
|
||||
/// CLIDebugger constructor - This initializes the debugger to its default
|
||||
/// state, and initializes the command table.
|
||||
///
|
||||
CLIDebugger::CLIDebugger(LLVMContext& ctxt)
|
||||
: Context(ctxt), TheProgramInfo(0), TheRuntimeInfo(0),
|
||||
Prompt("(llvm-db) "), ListSize(10) {
|
||||
// Initialize instance variables
|
||||
CurrentFile = 0;
|
||||
LineListedStart = 1;
|
||||
LineListedEnd = 1;
|
||||
LastCurrentFrame = 0;
|
||||
CurrentLanguage = 0;
|
||||
|
||||
CLICommand *C;
|
||||
//===--------------------------------------------------------------------===//
|
||||
// Program startup and shutdown options
|
||||
//
|
||||
addCommand("file", new BuiltinCLICommand(
|
||||
"Use specified file as the program to be debugged",
|
||||
"The debugger looks in the current directory and the program $PATH for the"
|
||||
" specified LLVM program. It then unloads the currently loaded program and"
|
||||
" loads the specified program.\n",
|
||||
&CLIDebugger::fileCommand));
|
||||
|
||||
addCommand("create", new BuiltinCLICommand(
|
||||
"Start the program, halting its execution in main",
|
||||
"This command creates an instance of the current program, but stops"
|
||||
"\nexecution immediately.\n",
|
||||
&CLIDebugger::createCommand));
|
||||
|
||||
addCommand("kill", new BuiltinCLICommand(
|
||||
"Kills the execution of the current program being debugged", "",
|
||||
&CLIDebugger::killCommand));
|
||||
|
||||
addCommand("quit", new BuiltinCLICommand(
|
||||
"Exit the debugger", "",
|
||||
&CLIDebugger::quitCommand));
|
||||
|
||||
//===--------------------------------------------------------------------===//
|
||||
// Program execution commands
|
||||
//
|
||||
addCommand("run", C = new BuiltinCLICommand(
|
||||
"Start the program running from the beginning", "",
|
||||
&CLIDebugger::runCommand));
|
||||
addCommand("r", C);
|
||||
|
||||
addCommand("cont", C = new BuiltinCLICommand(
|
||||
"Continue program being debugged until the next stop point", "",
|
||||
&CLIDebugger::contCommand));
|
||||
addCommand("c", C); addCommand("fg", C);
|
||||
|
||||
addCommand("step", C = new BuiltinCLICommand(
|
||||
"Step program until it reaches a new source line", "",
|
||||
&CLIDebugger::stepCommand));
|
||||
addCommand("s", C);
|
||||
|
||||
addCommand("next", C = new BuiltinCLICommand(
|
||||
"Step program until it reaches a new source line, stepping over calls", "",
|
||||
&CLIDebugger::nextCommand));
|
||||
addCommand("n", C);
|
||||
|
||||
addCommand("finish", new BuiltinCLICommand(
|
||||
"Execute until the selected stack frame returns",
|
||||
"Upon return, the value returned is printed and put in the value history.\n",
|
||||
&CLIDebugger::finishCommand));
|
||||
|
||||
//===--------------------------------------------------------------------===//
|
||||
// Stack frame commands
|
||||
//
|
||||
addCommand("backtrace", C = new BuiltinCLICommand(
|
||||
"Print backtrace of all stack frames, or innermost COUNT frames",
|
||||
"FIXME: describe. Takes 'n', '-n' or 'full'\n",
|
||||
&CLIDebugger::backtraceCommand));
|
||||
addCommand("bt", C);
|
||||
|
||||
addCommand("up", new BuiltinCLICommand(
|
||||
"Select and print stack frame that called this one",
|
||||
"An argument says how many frames up to go.\n",
|
||||
&CLIDebugger::upCommand));
|
||||
|
||||
addCommand("down", new BuiltinCLICommand(
|
||||
"Select and print stack frame called by this one",
|
||||
"An argument says how many frames down go.\n",
|
||||
&CLIDebugger::downCommand));
|
||||
|
||||
addCommand("frame", C = new BuiltinCLICommand(
|
||||
"Select and print a stack frame",
|
||||
"With no argument, print the selected stack frame. (See also 'info frame').\n"
|
||||
"An argument specifies the frame to select.\n",
|
||||
&CLIDebugger::frameCommand));
|
||||
addCommand("f", C);
|
||||
|
||||
//===--------------------------------------------------------------------===//
|
||||
// Breakpoint related commands
|
||||
//
|
||||
addCommand("break", C = new BuiltinCLICommand(
|
||||
"Set breakpoint at specified line or function",
|
||||
"FIXME: describe.\n",
|
||||
&CLIDebugger::breakCommand));
|
||||
addCommand("b", C);
|
||||
|
||||
|
||||
//===--------------------------------------------------------------------===//
|
||||
// Miscellaneous commands
|
||||
//
|
||||
addCommand("info", new BuiltinCLICommand(
|
||||
"Generic command for showing things about the program being debugged",
|
||||
"info functions: display information about functions in the program.\ninfo"
|
||||
" source : display information about the current source file.\ninfo source"
|
||||
"s : Display source file names for the program\ninfo target : print status"
|
||||
" of inferior process\n",
|
||||
&CLIDebugger::infoCommand));
|
||||
|
||||
addCommand("list", C = new BuiltinCLICommand(
|
||||
"List specified function or line",
|
||||
"FIXME: document\n",
|
||||
&CLIDebugger::listCommand));
|
||||
addCommand("l", C);
|
||||
|
||||
addCommand("set", new BuiltinCLICommand(
|
||||
"Change program or debugger variable",
|
||||
"FIXME: document\n",
|
||||
&CLIDebugger::setCommand));
|
||||
|
||||
addCommand("show", new BuiltinCLICommand(
|
||||
"Generic command for showing things about the debugger",
|
||||
"FIXME: document\n",
|
||||
&CLIDebugger::showCommand));
|
||||
|
||||
addCommand("help", C = new BuiltinCLICommand(
|
||||
"Prints information about available commands", "",
|
||||
&CLIDebugger::helpCommand));
|
||||
addCommand("h", C);
|
||||
}
|
||||
|
||||
|
||||
/// addCommand - Add a command to the CommandTable, potentially displacing a
|
||||
/// preexisting command.
|
||||
void CLIDebugger::addCommand(const std::string &Option, CLICommand *Cmd) {
|
||||
assert(Cmd && "Cannot set a null command!");
|
||||
CLICommand *&CS = CommandTable[Option];
|
||||
if (CS == Cmd) return; // noop
|
||||
|
||||
// If we already have a command, decrement the command's reference count.
|
||||
if (CS) {
|
||||
CS->removeOptionName(Option);
|
||||
CS->dropRef();
|
||||
}
|
||||
CS = Cmd;
|
||||
|
||||
// Remember that we are using this command.
|
||||
Cmd->addRef();
|
||||
Cmd->addOptionName(Option);
|
||||
}
|
||||
|
||||
static bool isValidPrefix(const std::string &Prefix, const std::string &Option){
|
||||
return Prefix.size() <= Option.size() &&
|
||||
Prefix == std::string(Option.begin(), Option.begin()+Prefix.size());
|
||||
}
|
||||
|
||||
/// getCommand - This looks up the specified command using a fuzzy match.
|
||||
/// If the string exactly matches a command or is an unambiguous prefix of a
|
||||
/// command, it returns the command. Otherwise it throws an exception
|
||||
/// indicating the possible ambiguous choices.
|
||||
CLICommand *CLIDebugger::getCommand(const std::string &Command) {
|
||||
|
||||
// Look up the command in the table.
|
||||
std::map<std::string, CLICommand*>::iterator CI =
|
||||
CommandTable.lower_bound(Command);
|
||||
|
||||
if (Command == "") {
|
||||
throw "Null command should not get here!";
|
||||
} else if (CI == CommandTable.end() ||
|
||||
!isValidPrefix(Command, CI->first)) {
|
||||
// If this command has no relation to anything in the command table,
|
||||
// print the error message.
|
||||
throw "Unknown command: '" + Command +
|
||||
"'. Use 'help' for list of commands.";
|
||||
} else if (CI->first == Command) {
|
||||
// We have an exact match on the command
|
||||
return CI->second;
|
||||
} else {
|
||||
// Otherwise, we have a prefix match. Check to see if this is
|
||||
// unambiguous, and if so, run it.
|
||||
std::map<std::string, CLICommand*>::iterator CI2 = CI;
|
||||
|
||||
// If the next command is a valid completion of this one, we are
|
||||
// ambiguous.
|
||||
if (++CI2 != CommandTable.end() && isValidPrefix(Command, CI2->first)) {
|
||||
std::string ErrorMsg =
|
||||
"Ambiguous command '" + Command + "'. Options: " + CI->first;
|
||||
for (++CI; CI != CommandTable.end() &&
|
||||
isValidPrefix(Command, CI->first); ++CI)
|
||||
ErrorMsg += ", " + CI->first;
|
||||
throw ErrorMsg;
|
||||
} else {
|
||||
// It's an unambiguous prefix of a command, use it.
|
||||
return CI->second;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// run - Start the debugger, returning when the user exits the debugger. This
|
||||
/// starts the main event loop of the CLI debugger.
|
||||
///
|
||||
int CLIDebugger::run() {
|
||||
std::string Command;
|
||||
std::cout << Prompt;
|
||||
|
||||
// Keep track of the last command issued, so that we can reissue it if the
|
||||
// user hits enter as the command.
|
||||
CLICommand *LastCommand = 0;
|
||||
std::string LastArgs;
|
||||
|
||||
// Continue reading commands until the end of file.
|
||||
while (getline(std::cin, Command)) {
|
||||
std::string Arguments = Command;
|
||||
|
||||
// Split off the command from the arguments to the command.
|
||||
Command = getToken(Arguments, " \t\n\v\f\r\\/;.*&");
|
||||
|
||||
try {
|
||||
CLICommand *CurCommand;
|
||||
|
||||
if (Command == "") {
|
||||
CurCommand = LastCommand;
|
||||
Arguments = LastArgs;
|
||||
} else {
|
||||
CurCommand = getCommand(Command);
|
||||
}
|
||||
|
||||
// Save the command we are running in case the user wants us to repeat it
|
||||
// next time.
|
||||
LastCommand = CurCommand;
|
||||
LastArgs = Arguments;
|
||||
|
||||
// Finally, execute the command.
|
||||
if (CurCommand)
|
||||
CurCommand->runCommand(*this, Arguments);
|
||||
|
||||
} catch (int RetVal) {
|
||||
// The quit command exits the command loop by throwing an integer return
|
||||
// code.
|
||||
return RetVal;
|
||||
} catch (const std::string &Error) {
|
||||
std::cout << "Error: " << Error << "\n";
|
||||
} catch (const char *Error) {
|
||||
std::cout << "Error: " << Error << "\n";
|
||||
} catch (const NonErrorException &E) {
|
||||
std::cout << E.getMessage() << "\n";
|
||||
} catch (...) {
|
||||
std::cout << "ERROR: Debugger caught unexpected exception!\n";
|
||||
// Attempt to continue.
|
||||
}
|
||||
|
||||
// Write the prompt to get the next bit of user input
|
||||
std::cout << Prompt;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/// askYesNo - Ask the user a question, and demand a yes/no response. If
|
||||
/// the user says yes, return true.
|
||||
///
|
||||
bool CLIDebugger::askYesNo(const std::string &Message) const {
|
||||
std::string Answer;
|
||||
std::cout << Message << " (y or n) " << std::flush;
|
||||
while (getline(std::cin, Answer)) {
|
||||
std::string Val = getToken(Answer);
|
||||
if (getToken(Answer).empty()) {
|
||||
if (Val == "yes" || Val == "y" || Val == "YES" || Val == "Y" ||
|
||||
Val == "Yes")
|
||||
return true;
|
||||
if (Val == "no" || Val == "n" || Val == "NO" || Val == "N" ||
|
||||
Val == "No")
|
||||
return false;
|
||||
}
|
||||
|
||||
std::cout << "Please answer y or n.\n" << Message << " (y or n) "
|
||||
<< std::flush;
|
||||
}
|
||||
|
||||
// Ran out of input?
|
||||
return false;
|
||||
}
|
@ -1,208 +0,0 @@
|
||||
//===- CLIDebugger.h - LLVM Command Line Interface Debugger -----*- C++ -*-===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This file defines the CLIDebugger class, which implements a command line
|
||||
// interface to the LLVM Debugger library.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef CLIDEBUGGER_H
|
||||
#define CLIDEBUGGER_H
|
||||
|
||||
#include "llvm/Debugger/Debugger.h"
|
||||
#include <map>
|
||||
|
||||
namespace llvm {
|
||||
class CLICommand;
|
||||
class SourceFile;
|
||||
struct SourceLanguage;
|
||||
class ProgramInfo;
|
||||
class RuntimeInfo;
|
||||
class LLVMContext;
|
||||
|
||||
/// CLIDebugger - This class implements the command line interface for the
|
||||
/// LLVM debugger.
|
||||
class CLIDebugger {
|
||||
LLVMContext& Context;
|
||||
|
||||
/// Dbg - The low-level LLVM debugger object that we use to do our dirty
|
||||
/// work.
|
||||
Debugger Dbg;
|
||||
|
||||
/// CommandTable - This table contains a mapping from command names to the
|
||||
/// CLICommand object that implements the command.
|
||||
std::map<std::string, CLICommand*> CommandTable;
|
||||
|
||||
//===------------------------------------------------------------------===//
|
||||
// Data related to the program that is currently loaded. Note that the Dbg
|
||||
// variable also captures some information about the loaded program. This
|
||||
// pointer is non-null iff Dbg.isProgramLoaded() is true.
|
||||
//
|
||||
ProgramInfo *TheProgramInfo;
|
||||
|
||||
//===------------------------------------------------------------------===//
|
||||
// Data related to the program that is currently executing, but has stopped.
|
||||
// Note that the Dbg variable also captures some information about the
|
||||
// loaded program. This pointer is non-null iff Dbg.isProgramRunning() is
|
||||
// true.
|
||||
//
|
||||
RuntimeInfo *TheRuntimeInfo;
|
||||
|
||||
/// LastCurrentFrame - This variable holds the Frame ID of the top-level
|
||||
/// stack frame from the last time that the program was executed. We keep
|
||||
/// this because we only want to print the source location when the current
|
||||
/// function changes.
|
||||
void *LastCurrentFrame;
|
||||
|
||||
//===------------------------------------------------------------------===//
|
||||
// Data directly exposed through the debugger prompt
|
||||
//
|
||||
std::string Prompt; // set prompt, show prompt
|
||||
unsigned ListSize; // set listsize, show listsize
|
||||
|
||||
//===------------------------------------------------------------------===//
|
||||
// Data to support user interaction
|
||||
//
|
||||
|
||||
/// CurrentFile - The current source file we are inspecting, or null if
|
||||
/// none.
|
||||
const SourceFile *CurrentFile;
|
||||
unsigned LineListedStart, LineListedEnd;
|
||||
|
||||
/// CurrentLanguage - This contains the source language in use, if one is
|
||||
/// explicitly set by the user. If this is null (the default), the language
|
||||
/// is automatically determined from the current stack frame.
|
||||
///
|
||||
const SourceLanguage *CurrentLanguage;
|
||||
|
||||
public:
|
||||
CLIDebugger(LLVMContext& ctxt);
|
||||
|
||||
/// getDebugger - Return the current LLVM debugger implementation being
|
||||
/// used.
|
||||
Debugger &getDebugger() { return Dbg; }
|
||||
|
||||
/// run - Start the debugger, returning when the user exits the debugger.
|
||||
/// This starts the main event loop of the CLI debugger.
|
||||
///
|
||||
int run();
|
||||
|
||||
/// addCommand - Add a command to the CommandTable, potentially displacing a
|
||||
/// preexisting command.
|
||||
void addCommand(const std::string &Option, CLICommand *Cmd);
|
||||
|
||||
/// addSourceDirectory - Add a directory to search when looking for the
|
||||
/// source code of the program.
|
||||
void addSourceDirectory(const std::string &Dir) {
|
||||
// FIXME: implement
|
||||
}
|
||||
|
||||
/// getCurrentLanguage - Return the current source language that the user is
|
||||
/// playing around with. This is aquired from the current stack frame of a
|
||||
/// running program if one exists, but this value can be explicitly set by
|
||||
/// the user as well.
|
||||
const SourceLanguage &getCurrentLanguage() const;
|
||||
|
||||
/// getProgramInfo - Return a reference to the ProgramInfo object for the
|
||||
/// currently loaded program. If there is no program loaded, throw an
|
||||
/// exception.
|
||||
ProgramInfo &getProgramInfo() const {
|
||||
if (TheProgramInfo == 0)
|
||||
throw "No program is loaded.";
|
||||
return *TheProgramInfo;
|
||||
}
|
||||
|
||||
/// getRuntimeInfo - Return a reference to the current RuntimeInfo object.
|
||||
/// If there is no program running, throw an exception.
|
||||
RuntimeInfo &getRuntimeInfo() const {
|
||||
if (TheRuntimeInfo == 0)
|
||||
throw "No program is running.";
|
||||
return *TheRuntimeInfo;
|
||||
}
|
||||
|
||||
private: // Internal implementation methods
|
||||
|
||||
/// getCommand - This looks up the specified command using a fuzzy match.
|
||||
/// If the string exactly matches a command or is an unambiguous prefix of a
|
||||
/// command, it returns the command. Otherwise it throws an exception
|
||||
/// indicating the possible ambiguous choices.
|
||||
CLICommand *getCommand(const std::string &Command);
|
||||
|
||||
/// askYesNo - Ask the user a question, and demand a yes/no response. If
|
||||
/// the user says yes, return true.
|
||||
bool askYesNo(const std::string &Message) const;
|
||||
|
||||
/// printProgramLocation - Given a loaded and created child process that has
|
||||
/// stopped, print its current source location.
|
||||
void printProgramLocation(bool PrintLocation = true);
|
||||
|
||||
/// eliminateRunInfo - We are about to run the program. Forget any state
|
||||
/// about how the program used to be stopped.
|
||||
void eliminateRunInfo();
|
||||
|
||||
/// programStoppedSuccessfully - This method updates internal data
|
||||
/// structures to reflect the fact that the program just executed a while,
|
||||
/// and has successfully stopped.
|
||||
void programStoppedSuccessfully();
|
||||
|
||||
public: /// Builtin debugger commands, invokable by the user
|
||||
// Program startup and shutdown options
|
||||
void fileCommand(std::string &Options); // file
|
||||
void createCommand(std::string &Options); // create
|
||||
void killCommand(std::string &Options); // kill
|
||||
void quitCommand(std::string &Options); // quit
|
||||
|
||||
// Program execution commands
|
||||
void runCommand(std::string &Options); // run|r
|
||||
void contCommand(std::string &Options); // cont|c|fg
|
||||
void stepCommand(std::string &Options); // step|s [count]
|
||||
void nextCommand(std::string &Options); // next|n [count]
|
||||
void finishCommand(std::string &Options); // finish
|
||||
|
||||
// Stack frame commands
|
||||
void backtraceCommand(std::string &Options); // backtrace|bt [count]
|
||||
void upCommand(std::string &Options); // up
|
||||
void downCommand(std::string &Options); // down
|
||||
void frameCommand(std::string &Options); // frame
|
||||
|
||||
|
||||
// Breakpoint related commands
|
||||
void breakCommand(std::string &Options); // break|b <id>
|
||||
|
||||
// Miscellaneous commands
|
||||
void infoCommand(std::string &Options); // info
|
||||
void listCommand(std::string &Options); // list
|
||||
void setCommand(std::string &Options); // set
|
||||
void showCommand(std::string &Options); // show
|
||||
void helpCommand(std::string &Options); // help
|
||||
|
||||
private:
|
||||
/// startProgramRunning - If the program has been updated, reload it, then
|
||||
/// start executing the program.
|
||||
void startProgramRunning();
|
||||
|
||||
/// printSourceLine - Print the specified line of the current source file.
|
||||
/// If the specified line is invalid (the source file could not be loaded or
|
||||
/// the line number is out of range), don't print anything, but return true.
|
||||
bool printSourceLine(unsigned LineNo);
|
||||
|
||||
/// parseLineSpec - Parses a line specifier, for use by the 'list' command.
|
||||
/// If SourceFile is returned as a void pointer, then it was not specified.
|
||||
/// If the line specifier is invalid, an exception is thrown.
|
||||
void parseLineSpec(std::string &LineSpec, const SourceFile *&SourceFile,
|
||||
unsigned &LineNo);
|
||||
|
||||
/// parseProgramOptions - This method parses the Options string and loads it
|
||||
/// as options to be passed to the program. This is used by the run command
|
||||
/// and by 'set args'.
|
||||
void parseProgramOptions(std::string &Options);
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
@ -1,8 +0,0 @@
|
||||
set(LLVM_LINK_COMPONENTS debugger)
|
||||
set(LLVM_REQUIRES_EH 1)
|
||||
|
||||
add_llvm_tool(llvm-db
|
||||
CLIDebugger.cpp
|
||||
Commands.cpp
|
||||
llvm-db.cpp
|
||||
)
|
@ -1,866 +0,0 @@
|
||||
//===-- Commands.cpp - Implement various commands for the CLI -------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This file implements many builtin user commands.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "CLIDebugger.h"
|
||||
#include "CLICommand.h"
|
||||
#include "llvm/Debugger/ProgramInfo.h"
|
||||
#include "llvm/Debugger/RuntimeInfo.h"
|
||||
#include "llvm/Debugger/SourceLanguage.h"
|
||||
#include "llvm/Debugger/SourceFile.h"
|
||||
#include "llvm/Debugger/InferiorProcess.h"
|
||||
#include "llvm/Support/FileUtilities.h"
|
||||
#include "llvm/Support/raw_ostream.h"
|
||||
#include "llvm/ADT/StringExtras.h"
|
||||
#include <cstdlib>
|
||||
using namespace llvm;
|
||||
|
||||
/// getCurrentLanguage - Return the current source language that the user is
|
||||
/// playing around with. This is aquired from the current stack frame of a
|
||||
/// running program if one exists, but this value can be explicitly set by the
|
||||
/// user as well.
|
||||
const SourceLanguage &CLIDebugger::getCurrentLanguage() const {
|
||||
// If the user explicitly switched languages with 'set language', use what
|
||||
// they asked for.
|
||||
if (CurrentLanguage) {
|
||||
return *CurrentLanguage;
|
||||
} else if (Dbg.isProgramRunning()) {
|
||||
// Otherwise, if the program is running, infer the current language from it.
|
||||
const GlobalVariable *FuncDesc =
|
||||
getRuntimeInfo().getCurrentFrame().getFunctionDesc();
|
||||
return getProgramInfo().getFunction(FuncDesc).getSourceFile().getLanguage();
|
||||
} else {
|
||||
// Otherwise, default to C like GDB apparently does.
|
||||
return SourceLanguage::getCFamilyInstance();
|
||||
}
|
||||
}
|
||||
|
||||
/// startProgramRunning - If the program has been updated, reload it, then
|
||||
/// start executing the program.
|
||||
void CLIDebugger::startProgramRunning() {
|
||||
eliminateRunInfo();
|
||||
|
||||
// If the program has been modified, reload it!
|
||||
sys::PathWithStatus Program(Dbg.getProgramPath());
|
||||
std::string Err;
|
||||
const sys::FileStatus *Status = Program.getFileStatus(false, &Err);
|
||||
if (!Status)
|
||||
throw Err;
|
||||
if (TheProgramInfo->getProgramTimeStamp() != Status->getTimestamp()) {
|
||||
outs() << "'" << Program.str() << "' has changed; re-reading program.\n";
|
||||
|
||||
// Unload an existing program. This kills the program if necessary.
|
||||
Dbg.unloadProgram();
|
||||
delete TheProgramInfo;
|
||||
TheProgramInfo = 0;
|
||||
CurrentFile = 0;
|
||||
|
||||
Dbg.loadProgram(Program.str(), Context);
|
||||
TheProgramInfo = new ProgramInfo(Dbg.getProgram());
|
||||
}
|
||||
|
||||
outs() << "Starting program: " << Dbg.getProgramPath() << "\n";
|
||||
Dbg.createProgram();
|
||||
|
||||
// There was no current frame.
|
||||
LastCurrentFrame = 0;
|
||||
}
|
||||
|
||||
/// printSourceLine - Print the specified line of the current source file.
|
||||
/// If the specified line is invalid (the source file could not be loaded or
|
||||
/// the line number is out of range), don't print anything, but return true.
|
||||
bool CLIDebugger::printSourceLine(unsigned LineNo) {
|
||||
assert(CurrentFile && "There is no current source file to print!");
|
||||
const char *LineStart, *LineEnd;
|
||||
CurrentFile->getSourceLine(LineNo-1, LineStart, LineEnd);
|
||||
if (LineStart == 0) return true;
|
||||
outs() << LineNo;
|
||||
|
||||
// If this is the line the program is currently stopped at, print a marker.
|
||||
if (Dbg.isProgramRunning()) {
|
||||
unsigned CurLineNo, CurColNo;
|
||||
const SourceFileInfo *CurSFI;
|
||||
getRuntimeInfo().getCurrentFrame().getSourceLocation(CurLineNo, CurColNo,
|
||||
CurSFI);
|
||||
|
||||
if (CurLineNo == LineNo && CurrentFile == &CurSFI->getSourceText())
|
||||
outs() << " ->";
|
||||
}
|
||||
|
||||
outs() << "\t" << std::string(LineStart, LineEnd) << "\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
/// printProgramLocation - Print a line of the place where the current stack
|
||||
/// frame has stopped and the source line it is on.
|
||||
///
|
||||
void CLIDebugger::printProgramLocation(bool PrintLocation) {
|
||||
assert(Dbg.isProgramLoaded() && Dbg.isProgramRunning() &&
|
||||
"Error program is not loaded and running!");
|
||||
|
||||
// Figure out where the program stopped...
|
||||
StackFrame &SF = getRuntimeInfo().getCurrentFrame();
|
||||
unsigned LineNo, ColNo;
|
||||
const SourceFileInfo *FileDesc;
|
||||
SF.getSourceLocation(LineNo, ColNo, FileDesc);
|
||||
|
||||
// If requested, print out some program information about WHERE we are.
|
||||
if (PrintLocation) {
|
||||
// FIXME: print the current function arguments
|
||||
if (const GlobalVariable *FuncDesc = SF.getFunctionDesc())
|
||||
outs() << getProgramInfo().getFunction(FuncDesc).getSymbolicName();
|
||||
else
|
||||
outs() << "<unknown function>";
|
||||
|
||||
CurrentFile = &FileDesc->getSourceText();
|
||||
|
||||
outs() << " at " << CurrentFile->getFilename() << ":" << LineNo;
|
||||
if (ColNo) outs() << ":" << ColNo;
|
||||
outs() << "\n";
|
||||
}
|
||||
|
||||
if (printSourceLine(LineNo))
|
||||
outs() << "<could not load source file>\n";
|
||||
else {
|
||||
LineListedStart = LineNo-ListSize/2+1;
|
||||
if ((int)LineListedStart < 1) LineListedStart = 1;
|
||||
LineListedEnd = LineListedStart+1;
|
||||
}
|
||||
}
|
||||
|
||||
/// eliminateRunInfo - We are about to run the program. Forget any state
|
||||
/// about how the program used to be stopped.
|
||||
void CLIDebugger::eliminateRunInfo() {
|
||||
delete TheRuntimeInfo;
|
||||
TheRuntimeInfo = 0;
|
||||
}
|
||||
|
||||
/// programStoppedSuccessfully - This method updates internal data
|
||||
/// structures to reflect the fact that the program just executed a while,
|
||||
/// and has successfully stopped.
|
||||
void CLIDebugger::programStoppedSuccessfully() {
|
||||
assert(TheRuntimeInfo==0 && "Someone forgot to release the old RuntimeInfo!");
|
||||
|
||||
TheRuntimeInfo = new RuntimeInfo(TheProgramInfo, Dbg.getRunningProcess());
|
||||
|
||||
// FIXME: if there are any breakpoints at the current location, print them as
|
||||
// well.
|
||||
|
||||
// Since the program as successfully stopped, print its location.
|
||||
void *CurrentFrame = getRuntimeInfo().getCurrentFrame().getFrameID();
|
||||
printProgramLocation(CurrentFrame != LastCurrentFrame);
|
||||
LastCurrentFrame = CurrentFrame;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// getUnsignedIntegerOption - Get an unsigned integer number from the Val
|
||||
/// string. Check to make sure that the string contains an unsigned integer
|
||||
/// token, and if not, throw an exception. If isOnlyOption is set, also throw
|
||||
/// an exception if there is extra junk at the end of the string.
|
||||
static unsigned getUnsignedIntegerOption(const char *Msg, std::string &Val,
|
||||
bool isOnlyOption = true) {
|
||||
std::string Tok = getToken(Val);
|
||||
if (Tok.empty() || (isOnlyOption && !getToken(Val).empty()))
|
||||
throw std::string(Msg) + " expects an unsigned integer argument.";
|
||||
|
||||
char *EndPtr;
|
||||
unsigned Result = strtoul(Tok.c_str(), &EndPtr, 0);
|
||||
if (EndPtr != Tok.c_str()+Tok.size())
|
||||
throw std::string(Msg) + " expects an unsigned integer argument.";
|
||||
|
||||
return Result;
|
||||
}
|
||||
|
||||
/// getOptionalUnsignedIntegerOption - This method is just like
|
||||
/// getUnsignedIntegerOption, but if the argument value is not specified, a
|
||||
/// default is returned instead of causing an error.
|
||||
static unsigned
|
||||
getOptionalUnsignedIntegerOption(const char *Msg, unsigned Default,
|
||||
std::string &Val, bool isOnlyOption = true) {
|
||||
// Check to see if the value was specified...
|
||||
std::string TokVal = getToken(Val);
|
||||
if (TokVal.empty()) return Default;
|
||||
|
||||
// If it was specified, add it back to the value we are parsing...
|
||||
Val = TokVal+Val;
|
||||
|
||||
// And parse normally.
|
||||
return getUnsignedIntegerOption(Msg, Val, isOnlyOption);
|
||||
}
|
||||
|
||||
|
||||
/// parseProgramOptions - This method parses the Options string and loads it
|
||||
/// as options to be passed to the program. This is used by the run command
|
||||
/// and by 'set args'.
|
||||
void CLIDebugger::parseProgramOptions(std::string &Options) {
|
||||
// FIXME: tokenizing by whitespace is clearly incorrect. Instead we should
|
||||
// honor quotes and other things that a shell would. Also in the future we
|
||||
// should support redirection of standard IO.
|
||||
|
||||
std::vector<std::string> Arguments;
|
||||
for (std::string A = getToken(Options); !A.empty(); A = getToken(Options))
|
||||
Arguments.push_back(A);
|
||||
Dbg.setProgramArguments(Arguments.begin(), Arguments.end());
|
||||
}
|
||||
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// Program startup and shutdown options
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
|
||||
/// file command - If the user specifies an option, search the PATH for the
|
||||
/// specified program/bitcode file and load it. If the user does not specify
|
||||
/// an option, unload the current program.
|
||||
void CLIDebugger::fileCommand(std::string &Options) {
|
||||
std::string Prog = getToken(Options);
|
||||
if (!getToken(Options).empty())
|
||||
throw "file command takes at most one argument.";
|
||||
|
||||
// Check to make sure the user knows what they are doing
|
||||
if (Dbg.isProgramRunning() &&
|
||||
!askYesNo("A program is already loaded. Kill it?"))
|
||||
return;
|
||||
|
||||
// Unload an existing program. This kills the program if necessary.
|
||||
eliminateRunInfo();
|
||||
delete TheProgramInfo;
|
||||
TheProgramInfo = 0;
|
||||
Dbg.unloadProgram();
|
||||
CurrentFile = 0;
|
||||
|
||||
// If requested, start the new program.
|
||||
if (Prog.empty()) {
|
||||
outs() << "Unloaded program.\n";
|
||||
} else {
|
||||
outs() << "Loading program... ";
|
||||
outs().flush();
|
||||
Dbg.loadProgram(Prog, Context);
|
||||
assert(Dbg.isProgramLoaded() &&
|
||||
"loadProgram succeeded, but not program loaded!");
|
||||
TheProgramInfo = new ProgramInfo(Dbg.getProgram());
|
||||
outs() << "successfully loaded '" << Dbg.getProgramPath() << "'!\n";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void CLIDebugger::createCommand(std::string &Options) {
|
||||
if (!getToken(Options).empty())
|
||||
throw "create command does not take any arguments.";
|
||||
if (!Dbg.isProgramLoaded()) throw "No program loaded.";
|
||||
if (Dbg.isProgramRunning() &&
|
||||
!askYesNo("The program is already running. Restart from the beginning?"))
|
||||
return;
|
||||
|
||||
// Start the program running.
|
||||
startProgramRunning();
|
||||
|
||||
// The program stopped!
|
||||
programStoppedSuccessfully();
|
||||
}
|
||||
|
||||
void CLIDebugger::killCommand(std::string &Options) {
|
||||
if (!getToken(Options).empty())
|
||||
throw "kill command does not take any arguments.";
|
||||
if (!Dbg.isProgramRunning())
|
||||
throw "No program is currently being run.";
|
||||
|
||||
if (askYesNo("Kill the program being debugged?"))
|
||||
Dbg.killProgram();
|
||||
eliminateRunInfo();
|
||||
}
|
||||
|
||||
void CLIDebugger::quitCommand(std::string &Options) {
|
||||
if (!getToken(Options).empty())
|
||||
throw "quit command does not take any arguments.";
|
||||
|
||||
if (Dbg.isProgramRunning() &&
|
||||
!askYesNo("The program is running. Exit anyway?"))
|
||||
return;
|
||||
|
||||
// Throw exception to get out of the user-input loop.
|
||||
throw 0;
|
||||
}
|
||||
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// Program execution commands
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
void CLIDebugger::runCommand(std::string &Options) {
|
||||
if (!Dbg.isProgramLoaded()) throw "No program loaded.";
|
||||
if (Dbg.isProgramRunning() &&
|
||||
!askYesNo("The program is already running. Restart from the beginning?"))
|
||||
return;
|
||||
|
||||
// Parse all of the options to the run command, which specify program
|
||||
// arguments to run with.
|
||||
parseProgramOptions(Options);
|
||||
|
||||
eliminateRunInfo();
|
||||
|
||||
// Start the program running.
|
||||
startProgramRunning();
|
||||
|
||||
// Start the program running...
|
||||
Options = "";
|
||||
contCommand(Options);
|
||||
}
|
||||
|
||||
void CLIDebugger::contCommand(std::string &Options) {
|
||||
if (!getToken(Options).empty()) throw "cont argument not supported yet.";
|
||||
if (!Dbg.isProgramRunning()) throw "Program is not running.";
|
||||
|
||||
eliminateRunInfo();
|
||||
|
||||
Dbg.contProgram();
|
||||
|
||||
// The program stopped!
|
||||
programStoppedSuccessfully();
|
||||
}
|
||||
|
||||
void CLIDebugger::stepCommand(std::string &Options) {
|
||||
if (!Dbg.isProgramRunning()) throw "Program is not running.";
|
||||
|
||||
// Figure out how many times to step.
|
||||
unsigned Amount =
|
||||
getOptionalUnsignedIntegerOption("'step' command", 1, Options);
|
||||
|
||||
eliminateRunInfo();
|
||||
|
||||
// Step the specified number of times.
|
||||
for (; Amount; --Amount)
|
||||
Dbg.stepProgram();
|
||||
|
||||
// The program stopped!
|
||||
programStoppedSuccessfully();
|
||||
}
|
||||
|
||||
void CLIDebugger::nextCommand(std::string &Options) {
|
||||
if (!Dbg.isProgramRunning()) throw "Program is not running.";
|
||||
unsigned Amount =
|
||||
getOptionalUnsignedIntegerOption("'next' command", 1, Options);
|
||||
|
||||
eliminateRunInfo();
|
||||
|
||||
for (; Amount; --Amount)
|
||||
Dbg.nextProgram();
|
||||
|
||||
// The program stopped!
|
||||
programStoppedSuccessfully();
|
||||
}
|
||||
|
||||
void CLIDebugger::finishCommand(std::string &Options) {
|
||||
if (!getToken(Options).empty())
|
||||
throw "finish command does not take any arguments.";
|
||||
if (!Dbg.isProgramRunning()) throw "Program is not running.";
|
||||
|
||||
// Figure out where we are exactly. If the user requests that we return from
|
||||
// a frame that is not the top frame, make sure we get it.
|
||||
void *CurrentFrame = getRuntimeInfo().getCurrentFrame().getFrameID();
|
||||
|
||||
eliminateRunInfo();
|
||||
|
||||
Dbg.finishProgram(CurrentFrame);
|
||||
|
||||
// The program stopped!
|
||||
programStoppedSuccessfully();
|
||||
}
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// Stack frame commands
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
void CLIDebugger::backtraceCommand(std::string &Options) {
|
||||
// Accepts "full", n, -n
|
||||
if (!getToken(Options).empty())
|
||||
throw "FIXME: bt command argument not implemented yet!";
|
||||
|
||||
RuntimeInfo &RI = getRuntimeInfo();
|
||||
ProgramInfo &PI = getProgramInfo();
|
||||
|
||||
try {
|
||||
for (unsigned i = 0; ; ++i) {
|
||||
StackFrame &SF = RI.getStackFrame(i);
|
||||
outs() << "#" << i;
|
||||
if (i == RI.getCurrentFrameIdx())
|
||||
outs() << " ->";
|
||||
outs() << "\t" << SF.getFrameID() << " in ";
|
||||
if (const GlobalVariable *G = SF.getFunctionDesc())
|
||||
outs() << PI.getFunction(G).getSymbolicName();
|
||||
|
||||
unsigned LineNo, ColNo;
|
||||
const SourceFileInfo *SFI;
|
||||
SF.getSourceLocation(LineNo, ColNo, SFI);
|
||||
if (!SFI->getBaseName().empty()) {
|
||||
outs() << " at " << SFI->getBaseName();
|
||||
if (LineNo) {
|
||||
outs() << ":" << LineNo;
|
||||
if (ColNo)
|
||||
outs() << ":" << ColNo;
|
||||
}
|
||||
}
|
||||
|
||||
// FIXME: when we support shared libraries, we should print ' from foo.so'
|
||||
// if the stack frame is from a different object than the current one.
|
||||
|
||||
outs() << "\n";
|
||||
}
|
||||
} catch (...) {
|
||||
// Stop automatically when we run off the bottom of the stack.
|
||||
}
|
||||
}
|
||||
|
||||
void CLIDebugger::upCommand(std::string &Options) {
|
||||
unsigned Num =
|
||||
getOptionalUnsignedIntegerOption("'up' command", 1, Options);
|
||||
|
||||
RuntimeInfo &RI = getRuntimeInfo();
|
||||
unsigned CurFrame = RI.getCurrentFrameIdx();
|
||||
|
||||
// Check to see if we go can up the specified number of frames.
|
||||
try {
|
||||
RI.getStackFrame(CurFrame+Num);
|
||||
} catch (...) {
|
||||
if (Num == 1)
|
||||
throw "Initial frame selected; you cannot go up.";
|
||||
else
|
||||
throw "Cannot go up " + utostr(Num) + " frames!";
|
||||
}
|
||||
|
||||
RI.setCurrentFrameIdx(CurFrame+Num);
|
||||
printProgramLocation();
|
||||
}
|
||||
|
||||
void CLIDebugger::downCommand(std::string &Options) {
|
||||
unsigned Num =
|
||||
getOptionalUnsignedIntegerOption("'down' command", 1, Options);
|
||||
|
||||
RuntimeInfo &RI = getRuntimeInfo();
|
||||
unsigned CurFrame = RI.getCurrentFrameIdx();
|
||||
|
||||
// Check to see if we can go up the specified number of frames.
|
||||
if (CurFrame < Num) {
|
||||
if (Num == 1)
|
||||
throw "Bottom (i.e., innermost) frame selected; you cannot go down.";
|
||||
else
|
||||
throw "Cannot go down " + utostr(Num) + " frames!";
|
||||
}
|
||||
|
||||
RI.setCurrentFrameIdx(CurFrame-Num);
|
||||
printProgramLocation();
|
||||
}
|
||||
|
||||
void CLIDebugger::frameCommand(std::string &Options) {
|
||||
RuntimeInfo &RI = getRuntimeInfo();
|
||||
unsigned CurFrame = RI.getCurrentFrameIdx();
|
||||
|
||||
unsigned Num =
|
||||
getOptionalUnsignedIntegerOption("'frame' command", CurFrame, Options);
|
||||
|
||||
// Check to see if we go to the specified frame.
|
||||
RI.getStackFrame(Num);
|
||||
|
||||
RI.setCurrentFrameIdx(Num);
|
||||
printProgramLocation();
|
||||
}
|
||||
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// Breakpoint related commands
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
void CLIDebugger::breakCommand(std::string &Options) {
|
||||
// Figure out where the user wants a breakpoint.
|
||||
const SourceFile *File;
|
||||
unsigned LineNo;
|
||||
|
||||
// Check to see if the user specified a line specifier.
|
||||
std::string Option = getToken(Options); // strip whitespace
|
||||
if (!Option.empty()) {
|
||||
Options = Option + Options; // reconstruct string
|
||||
|
||||
// Parse the line specifier.
|
||||
parseLineSpec(Options, File, LineNo);
|
||||
} else {
|
||||
// Build a line specifier for the current stack frame.
|
||||
throw "FIXME: breaking at the current location is not implemented yet!";
|
||||
}
|
||||
|
||||
if (!File) File = CurrentFile;
|
||||
if (File == 0)
|
||||
throw "Unknown file to place breakpoint!";
|
||||
|
||||
errs() << "Break: " << File->getFilename() << ":" << LineNo << "\n";
|
||||
|
||||
throw "breakpoints not implemented yet!";
|
||||
}
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// Miscellaneous commands
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
void CLIDebugger::infoCommand(std::string &Options) {
|
||||
std::string What = getToken(Options);
|
||||
|
||||
if (What.empty() || !getToken(Options).empty()){
|
||||
std::string infoStr("info");
|
||||
helpCommand(infoStr);
|
||||
return;
|
||||
}
|
||||
|
||||
if (What == "frame") {
|
||||
} else if (What == "functions") {
|
||||
const std::map<const GlobalVariable*, SourceFunctionInfo*> &Functions
|
||||
= getProgramInfo().getSourceFunctions();
|
||||
outs() << "All defined functions:\n";
|
||||
// FIXME: GDB groups these by source file. We could do that I guess.
|
||||
for (std::map<const GlobalVariable*, SourceFunctionInfo*>::const_iterator
|
||||
I = Functions.begin(), E = Functions.end(); I != E; ++I) {
|
||||
outs() << I->second->getSymbolicName() << "\n";
|
||||
}
|
||||
|
||||
} else if (What == "source") {
|
||||
if (CurrentFile == 0)
|
||||
throw "No current source file.";
|
||||
|
||||
// Get the SourceFile information for the current file.
|
||||
const SourceFileInfo &SF =
|
||||
getProgramInfo().getSourceFile(CurrentFile->getDescriptor());
|
||||
|
||||
outs() << "Current source file is: " << SF.getBaseName() << "\n"
|
||||
<< "Compilation directory is: " << SF.getDirectory() << "\n";
|
||||
if (unsigned NL = CurrentFile->getNumLines())
|
||||
outs() << "Located in: " << CurrentFile->getFilename() << "\n"
|
||||
<< "Contains " << NL << " lines\n";
|
||||
else
|
||||
outs() << "Could not find source file.\n";
|
||||
outs() << "Source language is "
|
||||
<< SF.getLanguage().getSourceLanguageName() << "\n";
|
||||
|
||||
} else if (What == "sources") {
|
||||
const std::map<const GlobalVariable*, SourceFileInfo*> &SourceFiles =
|
||||
getProgramInfo().getSourceFiles();
|
||||
outs() << "Source files for the program:\n";
|
||||
for (std::map<const GlobalVariable*, SourceFileInfo*>::const_iterator I =
|
||||
SourceFiles.begin(), E = SourceFiles.end(); I != E;) {
|
||||
outs() << I->second->getDirectory() << "/"
|
||||
<< I->second->getBaseName();
|
||||
++I;
|
||||
if (I != E) outs() << ", ";
|
||||
}
|
||||
outs() << "\n";
|
||||
} else if (What == "target") {
|
||||
outs() << Dbg.getRunningProcess().getStatus();
|
||||
} else {
|
||||
// See if this is something handled by the current language.
|
||||
if (getCurrentLanguage().printInfo(What))
|
||||
return;
|
||||
|
||||
throw "Unknown info command '" + What + "'. Try 'help info'.";
|
||||
}
|
||||
}
|
||||
|
||||
/// parseLineSpec - Parses a line specifier, for use by the 'list' command.
|
||||
/// If SourceFile is returned as a void pointer, then it was not specified.
|
||||
/// If the line specifier is invalid, an exception is thrown.
|
||||
void CLIDebugger::parseLineSpec(std::string &LineSpec,
|
||||
const SourceFile *&SourceFile,
|
||||
unsigned &LineNo) {
|
||||
SourceFile = 0;
|
||||
LineNo = 0;
|
||||
|
||||
// First, check to see if we have a : separator.
|
||||
std::string FirstPart = getToken(LineSpec, ":");
|
||||
std::string SecondPart = getToken(LineSpec, ":");
|
||||
if (!getToken(LineSpec).empty()) throw "Malformed line specification!";
|
||||
|
||||
// If there is no second part, we must have either "function", "number",
|
||||
// "+offset", or "-offset".
|
||||
if (SecondPart.empty()) {
|
||||
if (FirstPart.empty()) throw "Malformed line specification!";
|
||||
if (FirstPart[0] == '+') {
|
||||
FirstPart.erase(FirstPart.begin(), FirstPart.begin()+1);
|
||||
// For +n, return LineListedEnd+n
|
||||
LineNo = LineListedEnd +
|
||||
getUnsignedIntegerOption("Line specifier '+'", FirstPart);
|
||||
|
||||
} else if (FirstPart[0] == '-') {
|
||||
FirstPart.erase(FirstPart.begin(), FirstPart.begin()+1);
|
||||
// For -n, return LineListedEnd-n
|
||||
LineNo = LineListedEnd -
|
||||
getUnsignedIntegerOption("Line specifier '-'", FirstPart);
|
||||
if ((int)LineNo < 1) LineNo = 1;
|
||||
} else if (FirstPart[0] == '*') {
|
||||
throw "Address expressions not supported as source locations!";
|
||||
} else {
|
||||
// Ok, check to see if this is just a line number.
|
||||
std::string Saved = FirstPart;
|
||||
try {
|
||||
LineNo = getUnsignedIntegerOption("", Saved);
|
||||
} catch (...) {
|
||||
// Ok, it's not a valid line number. It must be a source-language
|
||||
// entity name.
|
||||
std::string Name = getToken(FirstPart);
|
||||
if (!getToken(FirstPart).empty())
|
||||
throw "Extra junk in line specifier after '" + Name + "'.";
|
||||
SourceFunctionInfo *SFI =
|
||||
getCurrentLanguage().lookupFunction(Name, getProgramInfo(),
|
||||
TheRuntimeInfo);
|
||||
if (SFI == 0)
|
||||
throw "Unknown identifier '" + Name + "'.";
|
||||
|
||||
unsigned L, C;
|
||||
SFI->getSourceLocation(L, C);
|
||||
if (L == 0) throw "Could not locate '" + Name + "'!";
|
||||
LineNo = L;
|
||||
SourceFile = &SFI->getSourceFile().getSourceText();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
// Ok, this must be a filename qualified line number or function name.
|
||||
// First, figure out the source filename.
|
||||
std::string SourceFilename = getToken(FirstPart);
|
||||
if (!getToken(FirstPart).empty())
|
||||
throw "Invalid filename qualified source location!";
|
||||
|
||||
// Next, check to see if this is just a line number.
|
||||
std::string Saved = SecondPart;
|
||||
try {
|
||||
LineNo = getUnsignedIntegerOption("", Saved);
|
||||
} catch (...) {
|
||||
// Ok, it's not a valid line number. It must be a function name.
|
||||
throw "FIXME: Filename qualified function names are not support "
|
||||
"as line specifiers yet!";
|
||||
}
|
||||
|
||||
// Ok, we got the line number. Now check out the source file name to make
|
||||
// sure it's all good. If it is, return it. If not, throw exception.
|
||||
SourceFile =&getProgramInfo().getSourceFile(SourceFilename).getSourceText();
|
||||
}
|
||||
}
|
||||
|
||||
void CLIDebugger::listCommand(std::string &Options) {
|
||||
if (!Dbg.isProgramLoaded())
|
||||
throw "No program is loaded. Use the 'file' command.";
|
||||
|
||||
// Handle "list foo," correctly, by returning " " as the second token
|
||||
Options += " ";
|
||||
|
||||
std::string FirstLineSpec = getToken(Options, ",");
|
||||
std::string SecondLineSpec = getToken(Options, ",");
|
||||
if (!getToken(Options, ",").empty())
|
||||
throw "list command only expects two source location specifiers!";
|
||||
|
||||
// StartLine, EndLine - The starting and ending line numbers to print.
|
||||
unsigned StartLine = 0, EndLine = 0;
|
||||
|
||||
if (SecondLineSpec.empty()) { // No second line specifier provided?
|
||||
// Handle special forms like "", "+", "-", etc.
|
||||
std::string TmpSpec = FirstLineSpec;
|
||||
std::string Tok = getToken(TmpSpec);
|
||||
if (getToken(TmpSpec).empty() && (Tok == "" || Tok == "+" || Tok == "-")) {
|
||||
if (Tok == "+" || Tok == "") {
|
||||
StartLine = LineListedEnd;
|
||||
EndLine = StartLine + ListSize;
|
||||
} else {
|
||||
assert(Tok == "-");
|
||||
StartLine = LineListedStart-ListSize;
|
||||
EndLine = LineListedStart;
|
||||
if ((int)StartLine <= 0) StartLine = 1;
|
||||
}
|
||||
} else {
|
||||
// Must be a normal line specifier.
|
||||
const SourceFile *File;
|
||||
unsigned LineNo;
|
||||
parseLineSpec(FirstLineSpec, File, LineNo);
|
||||
|
||||
// If the user only specified one file specifier, we should display
|
||||
// ListSize lines centered at the specified line.
|
||||
if (File != 0) CurrentFile = File;
|
||||
StartLine = LineNo - (ListSize+1)/2;
|
||||
if ((int)StartLine <= 0) StartLine = 1;
|
||||
EndLine = StartLine + ListSize;
|
||||
}
|
||||
|
||||
} else {
|
||||
// Parse two line specifiers...
|
||||
const SourceFile *StartFile, *EndFile;
|
||||
unsigned StartLineNo, EndLineNo;
|
||||
parseLineSpec(FirstLineSpec, StartFile, StartLineNo);
|
||||
unsigned SavedLLE = LineListedEnd;
|
||||
LineListedEnd = StartLineNo;
|
||||
try {
|
||||
parseLineSpec(SecondLineSpec, EndFile, EndLineNo);
|
||||
} catch (...) {
|
||||
LineListedEnd = SavedLLE;
|
||||
throw;
|
||||
}
|
||||
|
||||
// Inherit file specified by the first line spec if there was one.
|
||||
if (EndFile == 0) EndFile = StartFile;
|
||||
|
||||
if (StartFile != EndFile)
|
||||
throw "Start and end line specifiers are in different files!";
|
||||
CurrentFile = StartFile;
|
||||
StartLine = StartLineNo;
|
||||
EndLine = EndLineNo+1;
|
||||
}
|
||||
|
||||
assert((int)StartLine > 0 && (int)EndLine > 0 && StartLine <= EndLine &&
|
||||
"Error reading line specifiers!");
|
||||
|
||||
// If there was no current file, and the user didn't specify one to list, we
|
||||
// have an error.
|
||||
if (CurrentFile == 0)
|
||||
throw "There is no current file to list.";
|
||||
|
||||
// Remember for next time.
|
||||
LineListedStart = StartLine;
|
||||
LineListedEnd = StartLine;
|
||||
|
||||
for (unsigned LineNo = StartLine; LineNo != EndLine; ++LineNo) {
|
||||
// Print the source line, unless it is invalid.
|
||||
if (printSourceLine(LineNo))
|
||||
break;
|
||||
LineListedEnd = LineNo+1;
|
||||
}
|
||||
|
||||
// If we didn't print any lines, find out why.
|
||||
if (LineListedEnd == StartLine) {
|
||||
// See if we can read line #0 from the file, if not, we couldn't load the
|
||||
// file.
|
||||
const char *LineStart, *LineEnd;
|
||||
CurrentFile->getSourceLine(0, LineStart, LineEnd);
|
||||
if (LineStart == 0)
|
||||
throw "Could not load source file '" + CurrentFile->getFilename() + "'!";
|
||||
else
|
||||
outs() << "<end of file>\n";
|
||||
}
|
||||
}
|
||||
|
||||
void CLIDebugger::setCommand(std::string &Options) {
|
||||
std::string What = getToken(Options);
|
||||
|
||||
if (What.empty())
|
||||
throw "set command expects at least two arguments.";
|
||||
if (What == "args") {
|
||||
parseProgramOptions(Options);
|
||||
} else if (What == "language") {
|
||||
std::string Lang = getToken(Options);
|
||||
if (!getToken(Options).empty())
|
||||
throw "set language expects one argument at most.";
|
||||
if (Lang == "") {
|
||||
outs() << "The currently understood settings are:\n\n"
|
||||
<< "local or auto Automatic setting based on source file\n"
|
||||
<< "c Use the C language\n"
|
||||
<< "c++ Use the C++ language\n"
|
||||
<< "unknown Use when source language is not supported\n";
|
||||
} else if (Lang == "local" || Lang == "auto") {
|
||||
CurrentLanguage = 0;
|
||||
} else if (Lang == "c") {
|
||||
CurrentLanguage = &SourceLanguage::getCFamilyInstance();
|
||||
} else if (Lang == "c++") {
|
||||
CurrentLanguage = &SourceLanguage::getCPlusPlusInstance();
|
||||
} else if (Lang == "unknown") {
|
||||
CurrentLanguage = &SourceLanguage::getUnknownLanguageInstance();
|
||||
} else {
|
||||
throw "Unknown language '" + Lang + "'.";
|
||||
}
|
||||
|
||||
} else if (What == "listsize") {
|
||||
ListSize = getUnsignedIntegerOption("'set prompt' command", Options);
|
||||
} else if (What == "prompt") {
|
||||
// Include any trailing whitespace or other tokens, but not leading
|
||||
// whitespace.
|
||||
Prompt = getToken(Options); // Strip leading whitespace
|
||||
Prompt += Options; // Keep trailing whitespace or other stuff
|
||||
} else {
|
||||
// FIXME: Try to parse this as a source-language program expression.
|
||||
throw "Don't know how to set '" + What + "'!";
|
||||
}
|
||||
}
|
||||
|
||||
void CLIDebugger::showCommand(std::string &Options) {
|
||||
std::string What = getToken(Options);
|
||||
|
||||
if (What.empty() || !getToken(Options).empty())
|
||||
throw "show command expects one argument.";
|
||||
|
||||
if (What == "args") {
|
||||
outs() << "Argument list to give program when started is \"";
|
||||
// FIXME: This doesn't print stuff correctly if the arguments have spaces in
|
||||
// them, but currently the only way to get that is to use the --args command
|
||||
// line argument. This should really handle escaping all hard characters as
|
||||
// needed.
|
||||
for (unsigned i = 0, e = Dbg.getNumProgramArguments(); i != e; ++i)
|
||||
outs() << (i ? " " : "") << Dbg.getProgramArgument(i);
|
||||
outs() << "\"\n";
|
||||
|
||||
} else if (What == "language") {
|
||||
outs() << "The current source language is '";
|
||||
if (CurrentLanguage)
|
||||
outs() << CurrentLanguage->getSourceLanguageName();
|
||||
else
|
||||
outs() << "auto; currently "
|
||||
<< getCurrentLanguage().getSourceLanguageName();
|
||||
outs() << "'.\n";
|
||||
} else if (What == "listsize") {
|
||||
outs() << "Number of source lines llvm-db will list by default is "
|
||||
<< ListSize << ".\n";
|
||||
} else if (What == "prompt") {
|
||||
outs() << "llvm-db's prompt is \"" << Prompt << "\".\n";
|
||||
} else {
|
||||
throw "Unknown show command '" + What + "'. Try 'help show'.";
|
||||
}
|
||||
}
|
||||
|
||||
void CLIDebugger::helpCommand(std::string &Options) {
|
||||
// Print out all of the commands in the CommandTable
|
||||
std::string Command = getToken(Options);
|
||||
if (!getToken(Options).empty())
|
||||
throw "help command takes at most one argument.";
|
||||
|
||||
// Getting detailed help on a particular command?
|
||||
if (!Command.empty()) {
|
||||
CLICommand *C = getCommand(Command);
|
||||
outs() << C->getShortHelp() << ".\n" << C->getLongHelp();
|
||||
|
||||
// If there are aliases for this option, print them out.
|
||||
const std::vector<std::string> &Names = C->getOptionNames();
|
||||
if (Names.size() > 1) {
|
||||
outs() << "The '" << Command << "' command is known as: '"
|
||||
<< Names[0] << "'";
|
||||
for (unsigned i = 1, e = Names.size(); i != e; ++i)
|
||||
outs() << ", '" << Names[i] << "'";
|
||||
outs() << "\n";
|
||||
}
|
||||
|
||||
} else {
|
||||
unsigned MaxSize = 0;
|
||||
for (std::map<std::string, CLICommand*>::iterator I = CommandTable.begin(),
|
||||
E = CommandTable.end(); I != E; ++I)
|
||||
if (I->first.size() > MaxSize &&
|
||||
I->first == I->second->getPrimaryOptionName())
|
||||
MaxSize = I->first.size();
|
||||
|
||||
// Loop over all of the commands, printing the short help version
|
||||
for (std::map<std::string, CLICommand*>::iterator I = CommandTable.begin(),
|
||||
E = CommandTable.end(); I != E; ++I)
|
||||
if (I->first == I->second->getPrimaryOptionName())
|
||||
outs() << I->first << std::string(MaxSize - I->first.size(), ' ')
|
||||
<< " - " << I->second->getShortHelp() << "\n";
|
||||
}
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
##===- tools/llvm-db/Makefile ------------------------------*- Makefile -*-===##
|
||||
#
|
||||
# The LLVM Compiler Infrastructure
|
||||
#
|
||||
# This file is distributed under the University of Illinois Open Source
|
||||
# License. See LICENSE.TXT for details.
|
||||
#
|
||||
##===----------------------------------------------------------------------===##
|
||||
|
||||
LEVEL = ../..
|
||||
TOOLNAME = llvm-db
|
||||
LINK_COMPONENTS := debugger
|
||||
REQUIRES_EH := 1
|
||||
|
||||
include $(LEVEL)/Makefile.common
|
@ -1,102 +0,0 @@
|
||||
//===- llvm-db.cpp - LLVM Debugger ----------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This utility implements a simple text-mode front-end to the LLVM debugger
|
||||
// library.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "CLIDebugger.h"
|
||||
#include "llvm/LLVMContext.h"
|
||||
#include "llvm/Support/CommandLine.h"
|
||||
#include "llvm/Support/ManagedStatic.h"
|
||||
#include "llvm/Support/PrettyStackTrace.h"
|
||||
#include "llvm/Support/raw_ostream.h"
|
||||
#include "llvm/System/Signals.h"
|
||||
using namespace llvm;
|
||||
|
||||
namespace {
|
||||
// Command line options for specifying the program to debug and options to use
|
||||
cl::opt<std::string>
|
||||
InputFile(cl::desc("<program>"), cl::Positional, cl::init(""));
|
||||
|
||||
cl::list<std::string>
|
||||
InputArgs("args", cl::Positional, cl::desc("<program and arguments>"),
|
||||
cl::ZeroOrMore);
|
||||
|
||||
// Command line options to control various directory related stuff
|
||||
cl::list<std::string>
|
||||
SourceDirectories("directory", cl::value_desc("directory"),
|
||||
cl::desc("Add directory to the search for source files"));
|
||||
cl::alias SDA("d", cl::desc("Alias for --directory"),
|
||||
cl::aliasopt(SourceDirectories));
|
||||
|
||||
cl::opt<std::string>
|
||||
WorkingDirectory("cd", cl::desc("Use directory as current working directory"),
|
||||
cl::value_desc("directory"));
|
||||
|
||||
// Command line options specific to the llvm-db debugger driver
|
||||
cl::opt<bool> Quiet("quiet", cl::desc("Do not print introductory messages"));
|
||||
cl::alias QA1("silent", cl::desc("Alias for -quiet"), cl::aliasopt(Quiet));
|
||||
cl::alias QA2("q", cl::desc("Alias for -quiet"), cl::aliasopt(Quiet));
|
||||
}
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// main Driver function
|
||||
//
|
||||
int main(int argc, char **argv, char * const *envp) {
|
||||
// Print a stack trace if we signal out.
|
||||
sys::PrintStackTraceOnErrorSignal();
|
||||
PrettyStackTraceProgram X(argc, argv);
|
||||
|
||||
LLVMContext &Context = getGlobalContext();
|
||||
llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
|
||||
outs() << "NOTE: llvm-db is known useless right now.\n";
|
||||
try {
|
||||
cl::ParseCommandLineOptions(argc, argv,
|
||||
"llvm source-level debugger\n");
|
||||
|
||||
if (!Quiet)
|
||||
outs() << "llvm-db: The LLVM source-level debugger\n";
|
||||
|
||||
// Merge Inputfile and InputArgs into the InputArgs list...
|
||||
if (!InputFile.empty() && InputArgs.empty())
|
||||
InputArgs.push_back(InputFile);
|
||||
|
||||
// Create the CLI debugger...
|
||||
CLIDebugger D(Context);
|
||||
|
||||
// Initialize the debugger with the command line options we read...
|
||||
Debugger &Dbg = D.getDebugger();
|
||||
|
||||
// Initialize the debugger environment.
|
||||
Dbg.initializeEnvironment(envp);
|
||||
Dbg.setWorkingDirectory(WorkingDirectory);
|
||||
for (unsigned i = 0, e = SourceDirectories.size(); i != e; ++i)
|
||||
D.addSourceDirectory(SourceDirectories[i]);
|
||||
|
||||
if (!InputArgs.empty()) {
|
||||
try {
|
||||
D.fileCommand(InputArgs[0]);
|
||||
} catch (const std::string &Error) {
|
||||
outs() << "Error: " << Error << "\n";
|
||||
}
|
||||
|
||||
Dbg.setProgramArguments(InputArgs.begin()+1, InputArgs.end());
|
||||
}
|
||||
|
||||
// Now that we have initialized the debugger, run it.
|
||||
return D.run();
|
||||
} catch (const std::string& msg) {
|
||||
errs() << argv[0] << ": " << msg << "\n";
|
||||
} catch (...) {
|
||||
errs() << argv[0] << ": Unexpected unknown exception occurred.\n";
|
||||
}
|
||||
return 1;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user