LineEntry.h revision 296417
1//===-- LineEntry.h ---------------------------------------------*- C++ -*-===//
2//
3//                     The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef liblldb_LineEntry_h_
11#define liblldb_LineEntry_h_
12
13#include "lldb/lldb-private.h"
14#include "lldb/Core/AddressRange.h"
15#include "lldb/Host/FileSpec.h"
16
17namespace lldb_private {
18
19//----------------------------------------------------------------------
20/// @class LineEntry LineEntry.h "lldb/Symbol/LineEntry.h"
21/// @brief A line table entry class.
22//----------------------------------------------------------------------
23struct LineEntry
24{
25    //------------------------------------------------------------------
26    /// Default constructor.
27    ///
28    /// Initialize all member variables to invalid values.
29    //------------------------------------------------------------------
30    LineEntry ();
31
32    LineEntry
33    (
34        const lldb::SectionSP &section_sp,
35        lldb::addr_t section_offset,
36        lldb::addr_t byte_size,
37        const FileSpec &file,
38        uint32_t _line,
39        uint16_t _column,
40        bool _is_start_of_statement,
41        bool _is_start_of_basic_block,
42        bool _is_prologue_end,
43        bool _is_epilogue_begin,
44        bool _is_terminal_entry
45    );
46
47    //------------------------------------------------------------------
48    /// Clear the object's state.
49    ///
50    /// Clears all member variables to invalid values.
51    //------------------------------------------------------------------
52    void
53    Clear ();
54
55    //------------------------------------------------------------------
56    /// Dump a description of this object to a Stream.
57    ///
58    /// Dump a description of the contents of this object to the
59    /// supplied stream \a s.
60    ///
61    /// @param[in] s
62    ///     The stream to which to dump the object description.
63    ///
64    /// @param[in] comp_unit
65    ///     The compile unit object that contains the support file
66    ///     list so the line entry can dump the file name (since this
67    ///     object contains a file index into the support file list).
68    ///
69    /// @param[in] show_file
70    ///     If \b true, display the filename with the line entry which
71    ///     requires that the compile unit object \a comp_unit be a
72    ///     valid pointer.
73    ///
74    /// @param[in] style
75    ///     The display style for the section offset address.
76    ///
77    /// @return
78    ///     Returns \b true if the address was able to be displayed
79    ///     using \a style. File and load addresses may be unresolved
80    ///     and it may not be possible to display a valid address value.
81    ///     Returns \b false if the address was not able to be properly
82    ///     dumped.
83    ///
84    /// @see Address::DumpStyle
85    //------------------------------------------------------------------
86    bool
87    Dump (Stream *s, Target *target, bool show_file, Address::DumpStyle style, Address::DumpStyle fallback_style, bool show_range) const;
88
89    bool
90    GetDescription (Stream *s,
91                    lldb::DescriptionLevel level,
92                    CompileUnit* cu,
93                    Target *target,
94                    bool show_address_only) const;
95
96    //------------------------------------------------------------------
97    /// Dumps information specific to a process that stops at this
98    /// line entry to the supplied stream \a s.
99    ///
100    /// @param[in] s
101    ///     The stream to which to dump the object description.
102    ///
103    /// @param[in] comp_unit
104    ///     The compile unit object that contains the support file
105    ///     list so the line entry can dump the file name (since this
106    ///     object contains a file index into the support file list).
107    ///
108    /// @return
109    ///     Returns \b true if the file and line were properly dumped,
110    ///     \b false otherwise.
111    //------------------------------------------------------------------
112    bool
113    DumpStopContext (Stream *s, bool show_fullpaths) const;
114
115    //------------------------------------------------------------------
116    /// Check if a line entry object is valid.
117    ///
118    /// @return
119    ///     Returns \b true if the line entry contains a valid section
120    ///     offset address, file index, and line number, \b false
121    ///     otherwise.
122    //------------------------------------------------------------------
123    bool
124    IsValid () const;
125
126    //------------------------------------------------------------------
127    /// Compare two LineEntry objects.
128    ///
129    /// @param[in] lhs
130    ///     The Left Hand Side const LineEntry object reference.
131    ///
132    /// @param[in] rhs
133    ///     The Right Hand Side const LineEntry object reference.
134    ///
135    /// @return
136    ///     @li -1 if lhs < rhs
137    ///     @li 0 if lhs == rhs
138    ///     @li 1 if lhs > rhs
139    //------------------------------------------------------------------
140    static int
141    Compare (const LineEntry& lhs, const LineEntry& rhs);
142
143    //------------------------------------------------------------------
144    /// Give the range for this LineEntry + any additional LineEntries for
145    /// this same source line that are contiguous.
146    ///
147    /// A compiler may emit multiple line entries for a single source line,
148    /// e.g. to indicate subexpressions at different columns.  This method
149    /// will get the AddressRange for all of the LineEntries for this source
150    /// line that are contiguous.
151    //
152    /// Line entries with a line number of 0 are treated specially - these
153    /// are compiler-generated line table entries that the user did not
154    /// write in their source code, and we want to skip past in the debugger.
155    /// If this LineEntry is for line 32, and the following LineEntry is for
156    /// line 0, we will extend the range to include the AddressRange of the
157    /// line 0 LineEntry (and it will include the range of the following
158    /// LineEntries that match either 32 or 0.)
159    ///
160    /// If the initial LineEntry this method is called on is a line #0, only
161    /// the range of contiuous LineEntries with line #0 will be included in
162    /// the complete range.
163    ///
164    /// @return
165    ///     The contiguous AddressRange for this source line.
166    //------------------------------------------------------------------
167    AddressRange
168    GetSameLineContiguousAddressRange () const;
169
170    //------------------------------------------------------------------
171    // Member variables.
172    //------------------------------------------------------------------
173    AddressRange    range;                      ///< The section offset address range for this line entry.
174    FileSpec        file;
175    uint32_t        line;                       ///< The source line number, or zero if there is no line number information.
176    uint16_t        column;                     ///< The column number of the source line, or zero if there is no column information.
177    uint16_t        is_start_of_statement:1,    ///< Indicates this entry is the beginning of a statement.
178                    is_start_of_basic_block:1,  ///< Indicates this entry is the beginning of a basic block.
179                    is_prologue_end:1,          ///< Indicates this entry is one (of possibly many) where execution should be suspended for an entry breakpoint of a function.
180                    is_epilogue_begin:1,        ///< Indicates this entry is one (of possibly many) where execution should be suspended for an exit breakpoint of a function.
181                    is_terminal_entry:1;        ///< Indicates this entry is that of the first byte after the end of a sequence of target machine instructions.
182};
183
184//------------------------------------------------------------------
185/// Less than operator.
186///
187/// @param[in] lhs
188///     The Left Hand Side const LineEntry object reference.
189///
190/// @param[in] rhs
191///     The Right Hand Side const LineEntry object reference.
192///
193/// @return
194///     Returns \b true if lhs < rhs, false otherwise.
195//------------------------------------------------------------------
196bool operator<(const LineEntry& lhs, const LineEntry& rhs);
197
198} // namespace lldb_private
199
200#endif  // liblldb_LineEntry_h_
201