llvm.org GIT mirror llvm / 4575dcb
Initial implementation of some source-level debugging stuff git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@10684 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Lattner 16 years ago
6 changed file(s) with 887 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
0 //===- Debugger.h - LLVM debugger library interface -------------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file was developed by the LLVM research group and is distributed under
5 // the University of Illinois Open Source License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file defines the LLVM source-level debugger library interface.
10 //
11 //===----------------------------------------------------------------------===//
12
13 #ifndef LLVM_DEBUGGER_DEBUGGER_H
14 #define LLVM_DEBUGGER_DEBUGGER_H
15
16 #include
17 #include
18
19 namespace llvm {
20 class Module;
21 class InferiorProcess;
22
23 /// Debugger class - This class implements the LLVM source-level debugger.
24 /// This allows clients to handle the user IO processing without having to
25 /// worry about how the debugger itself works.
26 ///
27 class Debugger {
28 // State the debugger needs when starting and stopping the program.
29 std::vector ProgramArguments;
30
31 // The environment to run the program with. This should eventually be
32 // changed to vector of strings when we allow the user to edit the
33 // environment.
34 const char * const *Environment;
35
36 // Program - The currently loaded program, or null if none is loaded.
37 Module *Program;
38
39 // Process - The currently executing inferior process.
40 InferiorProcess *Process;
41
42 Debugger(const Debugger &); // DO NOT IMPLEMENT
43 void operator=(const Debugger &); // DO NOT IMPLEMENT
44 public:
45 Debugger();
46 ~Debugger();
47
48 //===------------------------------------------------------------------===//
49 // Methods for manipulating and inspecting the execution environment.
50 //
51
52 /// initializeEnvironment - Specify the environment the program should run
53 /// with. This is used to initialize the environment of the program to the
54 /// environment of the debugger.
55 void initializeEnvironment(const char *const *envp) {
56 Environment = envp;
57 }
58
59 /// setWorkingDirectory - Specify the working directory for the program to
60 /// be started from.
61 void setWorkingDirectory(const std::string &Dir) {
62 // FIXME: implement
63 }
64
65 template
66 void setProgramArguments(It I, It E) {
67 ProgramArguments.assign(I, E);
68 }
69
70
71 //===------------------------------------------------------------------===//
72 // Methods for manipulating and inspecting the program currently loaded.
73 //
74
75 /// isProgramLoaded - Return true if there is a program currently loaded.
76 ///
77 bool isProgramLoaded() const { return Program != 0; }
78
79 /// getProgram - Return the LLVM module corresponding to the program.
80 ///
81 Module *getProgram() const { return Program; }
82
83 /// getProgramPath - Get the path of the currently loaded program, or an
84 /// empty string if none is loaded.
85 std::string getProgramPath() const;
86
87 /// loadProgram - If a program is currently loaded, unload it. Then search
88 /// the PATH for the specified program, loading it when found. If the
89 /// specified program cannot be found, an exception is thrown to indicate
90 /// the error.
91 void loadProgram(const std::string &Path);
92
93 /// unloadProgram - If a program is running, kill it, then unload all traces
94 /// of the current program. If no program is loaded, this method silently
95 /// succeeds.
96 void unloadProgram();
97
98 //===------------------------------------------------------------------===//
99 // Methods for manipulating and inspecting the program currently running.
100 //
101 // If the program is running, and the debugger is active, then we know that
102 // the program has stopped. This being the case, we can inspect the
103 // program, ask it for its source location, set breakpoints, etc.
104 //
105
106 /// isProgramRunning - Return true if a program is loaded and has a
107 /// currently active instance.
108 bool isProgramRunning() const { return Process != 0; }
109
110 /// getRunningProcess - If there is no program running, throw an exception.
111 /// Otherwise return the running process so that it can be inspected by the
112 /// debugger.
113 const InferiorProcess &getRunningProcess() const {
114 if (Process == 0) throw "No process running.";
115 return *Process;
116 }
117
118 /// createProgram - Create an instance of the currently loaded program,
119 /// killing off any existing one. This creates the program and stops it at
120 /// the first possible moment. If there is no program loaded or if there is
121 /// a problem starting the program, this method throws an exception.
122 void createProgram();
123
124 /// killProgram - If the program is currently executing, kill off the
125 /// process and free up any state related to the currently running program.
126 /// If there is no program currently running, this just silently succeeds.
127 /// If something horrible happens when killing the program, an exception
128 /// gets thrown.
129 void killProgram();
130
131
132 //===------------------------------------------------------------------===//
133 // Methods for continuing execution. These methods continue the execution
134 // of the program by some amount. If the program is successfully stopped,
135 // execution returns, otherwise an exception is thrown.
136 //
137 // NOTE: These methods should always be used in preference to directly
138 // accessing the Dbg object, because these will delete the Process object if
139 // the process unexpectedly dies.
140 //
141
142 /// stepProgram - Implement the 'step' command, continuing execution until
143 /// the next possible stop point.
144 void stepProgram();
145
146 /// nextProgram - Implement the 'next' command, continuing execution until
147 /// the next possible stop point that is in the current function.
148 void nextProgram();
149
150 /// finishProgram - Implement the 'finish' command, continuing execution
151 /// until the specified frame ID returns.
152 void finishProgram(void *Frame);
153
154 /// contProgram - Implement the 'cont' command, continuing execution until
155 /// the next breakpoint is encountered.
156 void contProgram();
157 };
158
159 class NonErrorException {
160 std::string Message;
161 public:
162 NonErrorException(const std::string &M) : Message(M) {}
163 const std::string &getMessage() const { return Message; }
164 };
165
166 } // end namespace llvm
167
168 #endif
0 //===- InferiorProcess.h - Represent the program being debugged -*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file was developed by the LLVM research group and is distributed under
5 // the University of Illinois Open Source License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file defines the InferiorProcess class, which is used to represent,
10 // inspect, and manipulate a process under the control of the LLVM debugger.
11 //
12 // This is an abstract class which should allow various different types of
13 // implementations. Initially we implement a unix specific debugger backend
14 // that does not require code generator support, but we could eventually use
15 // code generator support with ptrace, support windows based targets, supported
16 // remote targets, etc.
17 //
18 // If the inferior process unexpectedly dies, an attempt to communicate with it
19 // will cause an InferiorProcessDead exception to be thrown, indicating the exit
20 // code of the process. When this occurs, no methods on the InferiorProcess
21 // class should be called except for the destructor.
22 //
23 //===----------------------------------------------------------------------===//
24
25 #ifndef LLVM_DEBUGGER_INFERIORPROCESS_H
26 #define LLVM_DEBUGGER_INFERIORPROCESS_H
27
28 #include
29 #include
30
31 namespace llvm {
32 class Module;
33 class GlobalVariable;
34
35 /// InferiorProcessDead exception - This class is thrown by methods that
36 /// communicate with the interior process if the process unexpectedly exits or
37 /// dies. The instance variable indicates what the exit code of the process
38 /// was, or -1 if unknown.
39 class InferiorProcessDead {
40 int ExitCode;
41 public:
42 InferiorProcessDead(int EC) : ExitCode(EC) {}
43 int getExitCode() const { return ExitCode; }
44 };
45
46 /// InferiorProcess class - This class represents the process being debugged
47 /// by the debugger. Objects of this class should not be stack allocated,
48 /// because the destructor can throw exceptions.
49 ///
50 class InferiorProcess {
51 Module *M;
52 protected:
53 InferiorProcess(Module *m) : M(m) {}
54 public:
55 /// create - Create an inferior process of the specified module, and
56 /// stop it at the first opportunity. If there is a problem starting the
57 /// program (for example, it has no main), throw an exception.
58 static InferiorProcess *create(Module *M,
59 const std::vector &Arguments,
60 const char * const *envp);
61
62 // InferiorProcess destructor - Kill the current process. If something
63 // terrible happens, we throw an exception from the destructor.
64 virtual ~InferiorProcess() {}
65
66 //===------------------------------------------------------------------===//
67 // Status methods - These methods return information about the currently
68 // stopped process.
69 //
70
71 /// getStatus - Return a status message that is specific to the current type
72 /// of inferior process that is created. This can return things like the
73 /// PID of the inferior or other potentially interesting things.
74 virtual std::string getStatus() const {
75 return "";
76 }
77
78 //===------------------------------------------------------------------===//
79 // Methods for inspecting the call stack.
80 //
81
82 /// getPreviousFrame - Given the descriptor for the current stack frame,
83 /// return the descriptor for the caller frame. This returns null when it
84 /// runs out of frames. If Frame is null, the initial frame should be
85 /// returned.
86 virtual void *getPreviousFrame(void *Frame) const = 0;
87
88 /// getSubprogramDesc - Return the subprogram descriptor for the current
89 /// stack frame.
90 virtual const GlobalVariable *getSubprogramDesc(void *Frame) const = 0;
91
92 /// getFrameLocation - This method returns the source location where each
93 /// stack frame is stopped.
94 virtual void getFrameLocation(void *Frame, unsigned &LineNo,
95 unsigned &ColNo,
96 const GlobalVariable *&SourceDesc) const = 0;
97
98 //===------------------------------------------------------------------===//
99 // Methods for manipulating breakpoints.
100 //
101
102 /// addBreakpoint - This method adds a breakpoint at the specified line,
103 /// column, and source file, and returns a unique identifier for it.
104 ///
105 /// It is up to the debugger to determine whether or not there is actually a
106 /// stop-point that corresponds with the specified location.
107 virtual unsigned addBreakpoint(unsigned LineNo, unsigned ColNo,
108 const GlobalVariable *SourceDesc) = 0;
109
110 /// removeBreakpoint - This deletes the breakpoint with the specified ID
111 /// number.
112 virtual void removeBreakpoint(unsigned ID) = 0;
113
114
115 //===------------------------------------------------------------------===//
116 // Execution methods - These methods cause the program to continue execution
117 // by some amount. If the program successfully stops, this returns.
118 // Otherwise, if the program unexpectedly terminates, an InferiorProcessDead
119 // exception is thrown.
120 //
121
122 /// stepProgram - Implement the 'step' command, continuing execution until
123 /// the next possible stop point.
124 virtual void stepProgram() = 0;
125
126 /// finishProgram - Implement the 'finish' command, continuing execution
127 /// until the current function returns.
128 virtual void finishProgram(void *Frame) = 0;
129
130 /// contProgram - Implement the 'cont' command, continuing execution until
131 /// a breakpoint is encountered.
132 virtual void contProgram() = 0;
133 };
134 } // end namespace llvm
135
136 #endif
137
0 //===- ProgramInfo.h - Information about the loaded program -----*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file was developed by the LLVM research group and is distributed under
5 // the University of Illinois Open Source License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file defines various pieces of information about the currently loaded
10 // program. One instance of this object is created every time a program is
11 // loaded, and destroyed every time it is unloaded.
12 //
13 // The various pieces of information gathered about the source program are all
14 // designed to be extended by various SourceLanguage implementations. This
15 // allows source languages to keep any extended information that they support in
16 // the derived class portions of the class.
17 //
18 //===----------------------------------------------------------------------===//
19
20 #ifndef LLVM_DEBUGGER_PROGRAMINFO_H
21 #define LLVM_DEBUGGER_PROGRAMINFO_H
22
23 #include
24 #include
25 #include
26
27 namespace llvm {
28 class GlobalVariable;
29 class Module;
30 class SourceFile;
31 class SourceLanguage;
32 class ProgramInfo;
33
34 /// SourceLanguageCache - SourceLanguage implementations are allowed to cache
35 /// stuff in the ProgramInfo object. The only requirement we have on these
36 /// instances is that they are destroyable.
37 struct SourceLanguageCache {
38 virtual ~SourceLanguageCache() {}
39 };
40
41 /// SourceFileInfo - One instance of this structure is created for each
42 /// source file in the program.
43 ///
44 class SourceFileInfo {
45 /// BaseName - The filename of the source file.
46 std::string BaseName;
47
48 /// Directory - The working directory of this source file when it was
49 /// compiled.
50 std::string Directory;
51
52 /// Version - The version of the LLVM debug information that this file was
53 /// compiled with.
54 unsigned Version;
55
56 /// Language - The source language that the file was compiled with. This
57 /// pointer is never null.
58 ///
59 const SourceLanguage *Language;
60
61 /// Descriptor - The LLVM Global Variable which describes the source file.
62 ///
63 const GlobalVariable *Descriptor;
64
65 /// SourceText - The body of this source file, or null if it has not yet
66 /// been loaded.
67 mutable SourceFile *SourceText;
68 public:
69 SourceFileInfo(const GlobalVariable *Desc, const SourceLanguage &Lang);
70 ~SourceFileInfo();
71
72 const std::string &getBaseName() const { return BaseName; }
73 const std::string &getDirectory() const { return Directory; }
74 unsigned getDebugVersion() const { return Version; }
75 const GlobalVariable *getDescriptor() const { return Descriptor; }
76 SourceFile &getSourceText() const;
77
78 const SourceLanguage &getLanguage() const { return *Language; }
79 };
80
81
82 /// SourceFunctionInfo - An instance of this class is used to represent each
83 /// source function in the program.
84 ///
85 class SourceFunctionInfo {
86 /// Name - This contains an abstract name that is potentially useful to the
87 /// end-user. If there is no explicit support for the current language,
88 /// then this string is used to identify the function.
89 std::string Name;
90
91 /// Descriptor - The descriptor for this function.
92 ///
93 const GlobalVariable *Descriptor;
94
95 /// SourceFile - The file that this function is defined in.
96 ///
97 const SourceFileInfo *SourceFile;
98
99 /// LineNo, ColNo - The location of the first stop-point in the function.
100 /// These are computed on demand.
101 mutable unsigned LineNo, ColNo;
102
103 public:
104 SourceFunctionInfo(ProgramInfo &PI, const GlobalVariable *Desc);
105 virtual ~SourceFunctionInfo() {}
106
107 /// getSymbolicName - Return a human-readable symbolic name to identify the
108 /// function (for example, in stack traces).
109 virtual std::string getSymbolicName() const { return Name; }
110
111 /// getDescriptor - This returns the descriptor for the function.
112 ///
113 const GlobalVariable *getDescriptor() const { return Descriptor; }
114
115 /// getSourceFile - This returns the source file that defines the function.
116 ///
117 const SourceFileInfo &getSourceFile() const { return *SourceFile; }
118
119 /// getSourceLocation - This method returns the location of the first
120 /// stopping point in the function. If the body of the function cannot be
121 /// found, this returns zeros for both values.
122 void getSourceLocation(unsigned &LineNo, unsigned &ColNo) const;
123 };
124
125
126 /// ProgramInfo - This object contains information about the loaded program.
127 /// When a new program is loaded, an instance of this class is created. When
128 /// the program is unloaded, the instance is destroyed. This object basically
129 /// manages the lazy computation of information useful for the debugger.
130 class ProgramInfo {
131 Module *M;
132
133 /// ProgramTimeStamp - This is the timestamp of the executable file that we
134 /// currently have loaded into the debugger.
135 unsigned long long ProgramTimeStamp;
136
137 /// SourceFiles - This map is used to transform source file descriptors into
138 /// their corresponding SourceFileInfo objects. This mapping owns the
139 /// memory for the SourceFileInfo objects.
140 ///
141 bool SourceFilesIsComplete;
142 std::map SourceFiles;
143
144 /// SourceFileIndex - Mapping from source file basenames to the information
145 /// about the file. Note that there can be filename collisions, so this is
146 /// a multimap. This map is populated incrementally as the user interacts
147 /// with the program, through the getSourceFileFromDesc method. If ALL of
148 /// the source files are needed, the getSourceFiles() method scans the
149 /// entire program looking for them.
150 ///
151 std::multimap SourceFileIndex;
152
153 /// SourceFunctions - This map contains entries functions in the source
154 /// program. If SourceFunctionsIsComplete is true, then this is ALL of the
155 /// functions in the program are in this map.
156 bool SourceFunctionsIsComplete;
157 std::map SourceFunctions;
158
159 /// LanguageCaches - Each source language is permitted to keep a per-program
160 /// cache of information specific to whatever it needs. This vector is
161 /// effectively a small map from the languages that are active in the
162 /// program to their caches. This can be accessed by the language by the
163 /// "getLanguageCache" method.
164 std::vector
165 SourceLanguageCache*> > LanguageCaches;
166 public:
167 ProgramInfo(Module *m);
168 ~ProgramInfo();
169
170 /// getProgramTimeStamp - Return the time-stamp of the program when it was
171 /// loaded.
172 unsigned long long getProgramTimeStamp() const { return ProgramTimeStamp; }
173
174 //===------------------------------------------------------------------===//
175 // Interfaces to the source code files that make up the program.
176 //
177
178 /// getSourceFile - Return source file information for the specified source
179 /// file descriptor object, adding it to the collection as needed. This
180 /// method always succeeds (is unambiguous), and is always efficient.
181 ///
182 const SourceFileInfo &getSourceFile(const GlobalVariable *Desc);
183
184 /// getSourceFile - Look up the file with the specified name. If there is
185 /// more than one match for the specified filename, prompt the user to pick
186 /// one. If there is no source file that matches the specified name, throw
187 /// an exception indicating that we can't find the file. Otherwise, return
188 /// the file information for that file.
189 ///
190 /// If the source file hasn't been discovered yet in the program, this
191 /// method might have to index the whole program by calling the
192 /// getSourceFiles() method.
193 ///
194 const SourceFileInfo &getSourceFile(const std::string &Filename);
195
196 /// getSourceFiles - Index all of the source files in the program and return
197 /// them. This information is lazily computed the first time that it is
198 /// requested. Since this information can take a long time to compute, the
199 /// user is given a chance to cancel it. If this occurs, an exception is
200 /// thrown.
201 const std::map &
202 getSourceFiles(bool RequiresCompleteMap = true);
203
204 //===------------------------------------------------------------------===//
205 // Interfaces to the functions that make up the program.
206 //
207
208 /// getFunction - Return source function information for the specified
209 /// function descriptor object, adding it to the collection as needed. This
210 /// method always succeeds (is unambiguous), and is always efficient.
211 ///
212 const SourceFunctionInfo &getFunction(const GlobalVariable *Desc);
213
214 /// getSourceFunctions - Index all of the functions in the program and
215 /// return them. This information is lazily computed the first time that it
216 /// is requested. Since this information can take a long time to compute,
217 /// the user is given a chance to cancel it. If this occurs, an exception
218 /// is thrown.
219 const std::map &
220 getSourceFunctions(bool RequiresCompleteMap = true);
221
222 /// addSourceFunctionsRead - Return true if the source functions map is
223 /// complete: that is, all functions in the program have been read in.
224 bool allSourceFunctionsRead() const { return SourceFunctionsIsComplete; }
225
226 /// getLanguageCache - This method is used to build per-program caches of
227 /// information, such as the functions or types visible to the program.
228 /// This can be used by SourceLanguage implementations because it requires
229 /// an accessible ::CacheType typedef, where is the C++ type of the
230 /// source-language subclass.
231 template
232 typename SL::CacheType &getLanguageCache(const SL *L) {
233 for (unsigned i = 0, e = LanguageCaches.size(); i != e; ++i)
234 if (LanguageCaches[i].first == L)
235 return *(typename SL::CacheType*)LanguageCaches[i].second;
236 typename SL::CacheType *NewCache = L->createSourceLanguageCache(*this);
237 LanguageCaches.push_back(std::make_pair(L, NewCache));
238 return *NewCache;
239 }
240 };
241
242 } // end namespace llvm
243
244 #endif
0 //===- RuntimeInfo.h - Information about running program --------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file was developed by the LLVM research group and is distributed under
5 // the University of Illinois Open Source License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file defines classes that capture various pieces of information about
10 // the currently executing, but stopped, program. One instance of this object
11 // is created every time a program is stopped, and destroyed every time it
12 // starts running again. This object's main goal is to make access to runtime
13 // information easy and efficient, by caching information as requested.
14 //
15 //===----------------------------------------------------------------------===//
16
17 #ifndef LLVM_DEBUGGER_RUNTIMEINFO_H
18 #define LLVM_DEBUGGER_RUNTIMEINFO_H
19
20 #include
21
22 namespace llvm {
23 class ProgramInfo;
24 class RuntimeInfo;
25 class InferiorProcess;
26 class GlobalVariable;
27 class SourceFileInfo;
28
29 /// StackFrame - One instance of this structure is created for each stack
30 /// frame that is active in the program.
31 ///
32 class StackFrame {
33 RuntimeInfo &RI;
34 void *FrameID;
35 const GlobalVariable *FunctionDesc;
36
37 /// LineNo, ColNo, FileInfo - This information indicates WHERE in the source
38 /// code for the program the stack frame is located.
39 unsigned LineNo, ColNo;
40 const SourceFileInfo *SourceInfo;
41 public:
42 StackFrame(RuntimeInfo &RI, void *ParentFrameID);
43
44 StackFrame &operator=(const StackFrame &RHS) {
45 FrameID = RHS.FrameID;
46 FunctionDesc = RHS.FunctionDesc;
47 return *this;
48 }
49
50 /// getFrameID - return the low-level opaque frame ID of this stack frame.
51 ///
52 void *getFrameID() const { return FrameID; }
53
54 /// getFunctionDesc - Return the descriptor for the function that contains
55 /// this stack frame, or null if it is unknown.
56 ///
57 const GlobalVariable *getFunctionDesc();
58
59 /// getSourceLocation - Return the source location that this stack frame is
60 /// sitting at.
61 void getSourceLocation(unsigned &LineNo, unsigned &ColNo,
62 const SourceFileInfo *&SourceInfo);
63 };
64
65
66 /// RuntimeInfo - This class collects information about the currently running
67 /// process. It is created whenever the program stops execution for the
68 /// debugger, and destroyed whenver execution continues.
69 class RuntimeInfo {
70 /// ProgInfo - This object contains static information about the program.
71 ///
72 ProgramInfo *ProgInfo;
73
74 /// IP - This object contains information about the actual inferior process
75 /// that we are communicating with and aggregating information from.
76 const InferiorProcess &IP;
77
78 /// CallStack - This caches information about the current stack trace of the
79 /// program. This is lazily computed as needed.
80 std::vector CallStack;
81
82 /// CurrentFrame - The user can traverse the stack frame with the
83 /// up/down/frame family of commands. This index indicates the current
84 /// stack frame.
85 unsigned CurrentFrame;
86
87 public:
88 RuntimeInfo(ProgramInfo *PI, const InferiorProcess &ip)
89 : ProgInfo(PI), IP(ip), CurrentFrame(0) {
90 // Make sure that the top of stack has been materialized. If this throws
91 // an exception, something is seriously wrong and the RuntimeInfo object
92 // would be unusable anyway.
93 getStackFrame(0);
94 }
95
96 ProgramInfo &getProgramInfo() { return *ProgInfo; }
97 const InferiorProcess &getInferiorProcess() const { return IP; }
98
99 //===------------------------------------------------------------------===//
100 // Methods for inspecting the call stack of the program.
101 //
102
103 /// getStackFrame - Materialize the specified stack frame and return it. If
104 /// the specified ID is off of the bottom of the stack, throw an exception
105 /// indicating the problem.
106 StackFrame &getStackFrame(unsigned ID) {
107 if (ID >= CallStack.size())
108 materializeFrame(ID);
109 return CallStack[ID];
110 }
111
112 /// getCurrentFrame - Return the current stack frame object that the user is
113 /// inspecting.
114 StackFrame &getCurrentFrame() {
115 assert(CallStack.size() > CurrentFrame &&
116 "Must have materialized frame before making it current!");
117 return CallStack[CurrentFrame];
118 }
119
120 /// getCurrentFrameIdx - Return the current frame the user is inspecting.
121 ///
122 unsigned getCurrentFrameIdx() const { return CurrentFrame; }
123
124 /// setCurrentFrameIdx - Set the current frame index to the specified value.
125 /// Note that the specified frame must have been materialized with
126 /// getStackFrame before it can be made current.
127 void setCurrentFrameIdx(unsigned Idx) {
128 assert(Idx < CallStack.size() &&
129 "Must materialize frame before making it current!");
130 CurrentFrame = Idx;
131 }
132 private:
133 /// materializeFrame - Create and process all frames up to and including the
134 /// specified frame number. This throws an exception if the specified frame
135 /// ID is nonexistant.
136 void materializeFrame(unsigned ID);
137 };
138 }
139
140 #endif
0 //===- SourceFile.h - Class to represent a source code file -----*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file was developed by the LLVM research group and is distributed under
5 // the University of Illinois Open Source License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file defines the SourceFile class which is used to represent a single
10 // file of source code in the program, caching data from the file to make access
11 // efficient.
12 //
13 //===----------------------------------------------------------------------===//
14
15 #ifndef LLVM_DEBUGGER_SOURCEFILE_H
16 #define LLVM_DEBUGGER_SOURCEFILE_H
17
18 #include
19 #include
20
21 namespace llvm {
22 class GlobalVariable;
23
24 class SourceFile {
25 /// Filename - This is the full path of the file that is loaded.
26 ///
27 std::string Filename;
28
29 /// Descriptor - The debugging descriptor for this source file. If there
30 /// are multiple descriptors for the same file, this is just the first one
31 /// encountered.
32 ///
33 const GlobalVariable *Descriptor;
34
35 /// FileStart, FileEnd - These pointers point to the start and end of the
36 /// file data for this file. If there was an error loading the file, these
37 /// pointers will both be null.
38 const char *FileStart, *FileEnd;
39
40 /// LineOffset - This vector contains a mapping from source line numbers to
41 /// their offsets in the file. This data is computed lazily, the first time
42 /// it is asked for. If there are zero elements allocated in this vector,
43 /// then it has not yet been computed.
44 mutable std::vector LineOffset;
45
46 public:
47 /// SourceFile constructor - Read in the specified source file if it exists,
48 /// but do not build the LineOffsets table until it is requested. This will
49 /// NOT throw an exception if the file is not found, if there is an error
50 /// reading it, or if the user cancels the operation. Instead, it will just
51 /// be an empty source file.
52 SourceFile(const std::string &fn, const GlobalVariable *Desc)
53 : Filename(fn), Descriptor(Desc), FileStart(0), FileEnd(0) {
54 readFile();
55 }
56 ~SourceFile() {
57 delete[] FileStart;
58 }
59
60 /// getDescriptor - Return the debugging decriptor for this source file.
61 ///
62 const GlobalVariable *getDescriptor() const { return Descriptor; }
63
64 /// getFilename - Return the fully resolved path that this file was loaded
65 /// from.
66 const std::string &getFilename() const { return Filename; }
67
68 /// getSourceLine - Given a line number, return the start and end of the
69 /// line in the file. If the line number is invalid, or if the file could
70 /// not be loaded, null pointers are returned for the start and end of the
71 /// file. Note that line numbers start with 0, not 1. This also strips off
72 /// any newlines from the end of the line, to ease formatting of the text.
73 void getSourceLine(unsigned LineNo, const char *&LineStart,
74 const char *&LineEnd) const;
75
76 /// getNumLines - Return the number of lines the source file contains.
77 ///
78 unsigned getNumLines() const {
79 if (LineOffset.empty()) calculateLineOffsets();
80 return LineOffset.size();
81 }
82
83 private:
84 /// readFile - Load Filename into FileStart and FileEnd.
85 ///
86 void readFile();
87
88 /// calculateLineOffsets - Compute the LineOffset vector for the current
89 /// file.
90 void calculateLineOffsets() const;
91 };
92 } // end namespace llvm
93
94 #endif
0 //===- SourceLanguage.h - Interact with source languages --------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file was developed by the LLVM research group and is distributed under
5 // the University of Illinois Open Source License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file defines the abstract SourceLanguage interface, which is used by the
10 // LLVM debugger to parse source-language expressions and render program objects
11 // into a human readable string. In general, these classes perform all of the
12 // analysis and interpretation of the language-specific debugger information.
13 //
14 // This interface is designed to be completely stateless, so all methods are
15 // const.
16 //
17 //===----------------------------------------------------------------------===//
18
19 #ifndef LLVM_DEBUGGER_SOURCELANGUAGE_H
20 #define LLVM_DEBUGGER_SOURCELANGUAGE_H
21
22 #include
23
24 namespace llvm {
25 class GlobalVariable;
26 class SourceFileInfo;
27 class SourceFunctionInfo;
28 class ProgramInfo;
29 class RuntimeInfo;
30
31 struct SourceLanguage {
32 virtual ~SourceLanguage() {}
33
34 /// getSourceLanguageName - This method is used to implement the 'show
35 /// language' command in the debugger.
36 virtual const char *getSourceLanguageName() const = 0;
37
38 //===------------------------------------------------------------------===//
39 // Methods used to implement debugger hooks.
40 //
41
42 /// printInfo - Implementing this method allows the debugger to use
43 /// language-specific 'info' extensions, e.g., 'info selectors' for objc.
44 /// This method should return true if the specified string is recognized.
45 ///
46 virtual bool printInfo(const std::string &What) const {
47 return false;
48 }
49
50 /// lookupFunction - Given a textual function name, return the
51 /// SourceFunctionInfo descriptor for that function, or null if it cannot be
52 /// found. If the program is currently running, the RuntimeInfo object
53 /// provides information about the current evaluation context, otherwise it
54 /// will be null.
55 ///
56 virtual SourceFunctionInfo *lookupFunction(const std::string &FunctionName,
57 ProgramInfo &PI,
58 RuntimeInfo *RI = 0) const {
59 return 0;
60 }
61
62
63 //===------------------------------------------------------------------===//
64 // Methods used to parse various pieces of program information.
65 //
66
67 /// createSourceFileInfo - This method can be implemented by the front-end
68 /// if it needs to keep track of information beyond what the debugger
69 /// requires.
70 virtual SourceFileInfo *
71 createSourceFileInfo(const GlobalVariable *Desc, ProgramInfo &PI) const;
72
73 /// createSourceFunctionInfo - This method can be implemented by the derived
74 /// SourceLanguage if it needs to keep track of more information than the
75 /// SourceFunctionInfo has.
76 virtual SourceFunctionInfo *
77 createSourceFunctionInfo(const GlobalVariable *Desc, ProgramInfo &PI) const;
78
79
80 //===------------------------------------------------------------------===//
81 // Static methods used to get instances of various source languages.
82 //
83
84 /// get - This method returns a source-language instance for the specified
85 /// Dwarf 3 language identifier. If the language is unknown, an object is
86 /// returned that can support some minimal operations, but is not terribly
87 /// bright.
88 static const SourceLanguage &get(unsigned ID);
89
90 /// get*Instance() - These methods return specific instances of languages.
91 ///
92 static const SourceLanguage &getCFamilyInstance();
93 static const SourceLanguage &getCPlusPlusInstance();
94 static const SourceLanguage &getUnknownLanguageInstance();
95 };
96 }
97
98 #endif