blob: 69f89968a5cef17345df9ac96ae53c05bb8d09b2 [file] [log] [blame]
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001//===-- Function.cpp --------------------------------------------*- 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#include "lldb/Symbol/Function.h"
Greg Clayton44d93782014-01-27 23:43:24 +000011#include "lldb/Core/Disassembler.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000012#include "lldb/Core/Module.h"
13#include "lldb/Core/Section.h"
Greg Claytone38a5ed2012-01-05 03:57:59 +000014#include "lldb/Host/Host.h"
Greg Claytona1e5dc82015-08-11 22:53:00 +000015#include "lldb/Symbol/CompilerType.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000016#include "lldb/Symbol/CompileUnit.h"
17#include "lldb/Symbol/LineTable.h"
Sean Callanan72e49402011-08-05 23:43:37 +000018#include "lldb/Symbol/SymbolFile.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000019#include "lldb/Symbol/SymbolVendor.h"
Sean Callanancc427fa2011-07-30 02:42:06 +000020#include "llvm/Support/Casting.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000021
Greg Claytonc9800662010-09-10 01:30:46 +000022using namespace lldb;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000023using namespace lldb_private;
24
25//----------------------------------------------------------------------
26// Basic function information is contained in the FunctionInfo class.
27// It is designed to contain the name, linkage name, and declaration
28// location.
29//----------------------------------------------------------------------
30FunctionInfo::FunctionInfo (const char *name, const Declaration *decl_ptr) :
31 m_name(name),
32 m_declaration(decl_ptr)
33{
34}
35
36
37FunctionInfo::FunctionInfo (const ConstString& name, const Declaration *decl_ptr) :
38 m_name(name),
39 m_declaration(decl_ptr)
40{
41}
42
43
44FunctionInfo::~FunctionInfo()
45{
46}
47
48void
Greg Clayton6dbd3982010-09-15 05:51:24 +000049FunctionInfo::Dump(Stream *s, bool show_fullpaths) const
Chris Lattner30fdc8d2010-06-08 16:52:24 +000050{
51 if (m_name)
52 *s << ", name = \"" << m_name << "\"";
Greg Clayton6dbd3982010-09-15 05:51:24 +000053 m_declaration.Dump(s, show_fullpaths);
Chris Lattner30fdc8d2010-06-08 16:52:24 +000054}
55
56
57int
58FunctionInfo::Compare(const FunctionInfo& a, const FunctionInfo& b)
59{
60 int result = ConstString::Compare(a.GetName(), b.GetName());
61 if (result)
62 return result;
63
64 return Declaration::Compare(a.m_declaration, b.m_declaration);
65}
66
67
68Declaration&
69FunctionInfo::GetDeclaration()
70{
71 return m_declaration;
72}
73
74const Declaration&
75FunctionInfo::GetDeclaration() const
76{
77 return m_declaration;
78}
79
Greg Claytonddaf6a72015-07-08 22:32:23 +000080ConstString
Chris Lattner30fdc8d2010-06-08 16:52:24 +000081FunctionInfo::GetName() const
82{
83 return m_name;
84}
85
86size_t
87FunctionInfo::MemorySize() const
88{
89 return m_name.MemorySize() + m_declaration.MemorySize();
90}
91
92
93InlineFunctionInfo::InlineFunctionInfo
94(
95 const char *name,
96 const char *mangled,
97 const Declaration *decl_ptr,
98 const Declaration *call_decl_ptr
99) :
100 FunctionInfo(name, decl_ptr),
Greg Clayton037520e2012-07-18 23:18:10 +0000101 m_mangled(ConstString(mangled), true),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000102 m_call_decl (call_decl_ptr)
103{
104}
105
106InlineFunctionInfo::InlineFunctionInfo
107(
108 const ConstString& name,
109 const Mangled &mangled,
110 const Declaration *decl_ptr,
111 const Declaration *call_decl_ptr
112) :
113 FunctionInfo(name, decl_ptr),
114 m_mangled(mangled),
115 m_call_decl (call_decl_ptr)
116{
117}
118
119InlineFunctionInfo::~InlineFunctionInfo()
120{
121}
122
123int
124InlineFunctionInfo::Compare(const InlineFunctionInfo& a, const InlineFunctionInfo& b)
125{
126
127 int result = FunctionInfo::Compare(a, b);
128 if (result)
129 return result;
130 // only compare the mangled names if both have them
131 return Mangled::Compare(a.m_mangled, a.m_mangled);
132}
133
134void
Greg Clayton6dbd3982010-09-15 05:51:24 +0000135InlineFunctionInfo::Dump(Stream *s, bool show_fullpaths) const
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000136{
Greg Clayton6dbd3982010-09-15 05:51:24 +0000137 FunctionInfo::Dump(s, show_fullpaths);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000138 if (m_mangled)
139 m_mangled.Dump(s);
140}
141
142void
Greg Claytonddaf6a72015-07-08 22:32:23 +0000143InlineFunctionInfo::DumpStopContext (Stream *s, LanguageType language) const
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000144{
145// s->Indent("[inlined] ");
146 s->Indent();
147 if (m_mangled)
Greg Claytonddaf6a72015-07-08 22:32:23 +0000148 s->PutCString (m_mangled.GetName(language).AsCString());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000149 else
150 s->PutCString (m_name.AsCString());
151}
152
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000153
Greg Claytonddaf6a72015-07-08 22:32:23 +0000154ConstString
155InlineFunctionInfo::GetName (LanguageType language) const
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000156{
157 if (m_mangled)
Greg Claytonddaf6a72015-07-08 22:32:23 +0000158 return m_mangled.GetName(language);
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000159 return m_name;
160}
161
Enrico Granatac1f705c2015-07-06 18:28:46 +0000162ConstString
Greg Claytonddaf6a72015-07-08 22:32:23 +0000163InlineFunctionInfo::GetDisplayName (LanguageType language) const
Enrico Granatac1f705c2015-07-06 18:28:46 +0000164{
165 if (m_mangled)
Greg Claytonddaf6a72015-07-08 22:32:23 +0000166 return m_mangled.GetDisplayDemangledName(language);
Enrico Granatac1f705c2015-07-06 18:28:46 +0000167 return m_name;
168}
Greg Clayton1b72fcb2010-08-24 00:45:41 +0000169
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000170Declaration &
171InlineFunctionInfo::GetCallSite ()
172{
173 return m_call_decl;
174}
175
176const Declaration &
177InlineFunctionInfo::GetCallSite () const
178{
179 return m_call_decl;
180}
181
182
183Mangled&
184InlineFunctionInfo::GetMangled()
185{
186 return m_mangled;
187}
188
189const Mangled&
190InlineFunctionInfo::GetMangled() const
191{
192 return m_mangled;
193}
194
195size_t
196InlineFunctionInfo::MemorySize() const
197{
198 return FunctionInfo::MemorySize() + m_mangled.MemorySize();
199}
200
201//----------------------------------------------------------------------
202//
203//----------------------------------------------------------------------
204Function::Function
205(
206 CompileUnit *comp_unit,
207 lldb::user_id_t func_uid,
208 lldb::user_id_t type_uid,
209 const Mangled &mangled,
210 Type * type,
211 const AddressRange& range
212) :
Greg Clayton0b76a2c2010-08-21 02:22:51 +0000213 UserID (func_uid),
214 m_comp_unit (comp_unit),
215 m_type_uid (type_uid),
216 m_type (type),
217 m_mangled (mangled),
218 m_block (func_uid),
219 m_range (range),
Tamas Berghammer35d9d2d2015-08-25 11:46:06 +0000220 m_frame_base (nullptr),
Greg Clayton0b76a2c2010-08-21 02:22:51 +0000221 m_flags (),
222 m_prologue_byte_size (0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000223{
Greg Clayton0b76a2c2010-08-21 02:22:51 +0000224 m_block.SetParentScope(this);
Ed Masted4612ad2014-04-20 13:17:36 +0000225 assert(comp_unit != nullptr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000226}
227
228Function::Function
229(
230 CompileUnit *comp_unit,
231 lldb::user_id_t func_uid,
232 lldb::user_id_t type_uid,
233 const char *mangled,
234 Type *type,
235 const AddressRange &range
236) :
Greg Clayton0b76a2c2010-08-21 02:22:51 +0000237 UserID (func_uid),
238 m_comp_unit (comp_unit),
239 m_type_uid (type_uid),
240 m_type (type),
Greg Clayton037520e2012-07-18 23:18:10 +0000241 m_mangled (ConstString(mangled), true),
Greg Clayton0b76a2c2010-08-21 02:22:51 +0000242 m_block (func_uid),
243 m_range (range),
Tamas Berghammer35d9d2d2015-08-25 11:46:06 +0000244 m_frame_base (nullptr),
Greg Clayton0b76a2c2010-08-21 02:22:51 +0000245 m_flags (),
246 m_prologue_byte_size (0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000247{
Greg Clayton0b76a2c2010-08-21 02:22:51 +0000248 m_block.SetParentScope(this);
Ed Masted4612ad2014-04-20 13:17:36 +0000249 assert(comp_unit != nullptr);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000250}
251
252
253Function::~Function()
254{
255}
256
Jim Ingham99760332010-08-20 01:15:01 +0000257void
258Function::GetStartLineSourceInfo (FileSpec &source_file, uint32_t &line_no)
259{
260 line_no = 0;
261 source_file.Clear();
262
Ed Masted4612ad2014-04-20 13:17:36 +0000263 if (m_comp_unit == nullptr)
Jim Ingham99760332010-08-20 01:15:01 +0000264 return;
265
Ed Masted4612ad2014-04-20 13:17:36 +0000266 if (m_type != nullptr && m_type->GetDeclaration().GetLine() != 0)
Jim Ingham99760332010-08-20 01:15:01 +0000267 {
268 source_file = m_type->GetDeclaration().GetFile();
269 line_no = m_type->GetDeclaration().GetLine();
270 }
271 else
272 {
273 LineTable *line_table = m_comp_unit->GetLineTable();
Ed Masted4612ad2014-04-20 13:17:36 +0000274 if (line_table == nullptr)
Jim Ingham99760332010-08-20 01:15:01 +0000275 return;
276
277 LineEntry line_entry;
Ed Masted4612ad2014-04-20 13:17:36 +0000278 if (line_table->FindLineEntryByAddress (GetAddressRange().GetBaseAddress(), line_entry, nullptr))
Jim Ingham99760332010-08-20 01:15:01 +0000279 {
280 line_no = line_entry.line;
281 source_file = line_entry.file;
282 }
283 }
284}
285
286void
287Function::GetEndLineSourceInfo (FileSpec &source_file, uint32_t &line_no)
288{
289 line_no = 0;
290 source_file.Clear();
291
292 // The -1 is kind of cheesy, but I want to get the last line entry for the given function, not the
293 // first entry of the next.
294 Address scratch_addr(GetAddressRange().GetBaseAddress());
295 scratch_addr.SetOffset (scratch_addr.GetOffset() + GetAddressRange().GetByteSize() - 1);
296
297 LineTable *line_table = m_comp_unit->GetLineTable();
Ed Masted4612ad2014-04-20 13:17:36 +0000298 if (line_table == nullptr)
Jim Ingham99760332010-08-20 01:15:01 +0000299 return;
300
301 LineEntry line_entry;
Ed Masted4612ad2014-04-20 13:17:36 +0000302 if (line_table->FindLineEntryByAddress (scratch_addr, line_entry, nullptr))
Jim Ingham99760332010-08-20 01:15:01 +0000303 {
304 line_no = line_entry.line;
305 source_file = line_entry.file;
306 }
307}
308
Greg Clayton0b76a2c2010-08-21 02:22:51 +0000309Block &
310Function::GetBlock (bool can_create)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000311{
Greg Clayton0b76a2c2010-08-21 02:22:51 +0000312 if (!m_block.BlockInfoHasBeenParsed() && can_create)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000313 {
314 SymbolContext sc;
315 CalculateSymbolContext(&sc);
Greg Clayton17cc8b92011-06-24 03:47:23 +0000316 if (sc.module_sp)
317 {
318 sc.module_sp->GetSymbolVendor()->ParseFunctionBlocks(sc);
319 }
320 else
321 {
Greg Claytone38a5ed2012-01-05 03:57:59 +0000322 Host::SystemLog (Host::eSystemLogError,
Greg Claytonb5ad4ec2013-04-29 17:25:54 +0000323 "error: unable to find module shared pointer for function '%s' in %s\n",
Greg Claytone38a5ed2012-01-05 03:57:59 +0000324 GetName().GetCString(),
Greg Claytonb5ad4ec2013-04-29 17:25:54 +0000325 m_comp_unit->GetPath().c_str());
Greg Clayton17cc8b92011-06-24 03:47:23 +0000326 }
Greg Clayton0b76a2c2010-08-21 02:22:51 +0000327 m_block.SetBlockInfoHasBeenParsed (true, true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000328 }
Greg Clayton0b76a2c2010-08-21 02:22:51 +0000329 return m_block;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000330}
331
332CompileUnit*
333Function::GetCompileUnit()
334{
335 return m_comp_unit;
336}
337
338const CompileUnit*
339Function::GetCompileUnit() const
340{
341 return m_comp_unit;
342}
343
Greg Clayton0c5cd902010-06-28 21:30:43 +0000344
345void
Greg Claytonf5e56de2010-09-14 23:36:40 +0000346Function::GetDescription(Stream *s, lldb::DescriptionLevel level, Target *target)
Greg Clayton0c5cd902010-06-28 21:30:43 +0000347{
348 Type* func_type = GetType();
Jim Ingham28eb5712012-10-12 17:34:26 +0000349 const char *name = func_type ? func_type->GetName().AsCString() : "<unknown>";
350
351 *s << "id = " << (const UserID&)*this << ", name = \"" << name << "\", range = ";
Greg Claytonc9800662010-09-10 01:30:46 +0000352
353 Address::DumpStyle fallback_style;
354 if (level == eDescriptionLevelVerbose)
355 fallback_style = Address::DumpStyleModuleWithFileAddress;
356 else
357 fallback_style = Address::DumpStyleFileAddress;
Greg Claytonf5e56de2010-09-14 23:36:40 +0000358 GetAddressRange().Dump(s, target, Address::DumpStyleLoadAddress, fallback_style);
Greg Clayton0c5cd902010-06-28 21:30:43 +0000359}
360
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000361void
362Function::Dump(Stream *s, bool show_context) const
363{
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000364 s->Printf("%p: ", static_cast<const void*>(this));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000365 s->Indent();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000366 *s << "Function" << static_cast<const UserID&>(*this);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000367
368 m_mangled.Dump(s);
369
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000370 if (m_type)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000371 s->Printf(", type = %p", static_cast<void*>(m_type));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000372 else if (m_type_uid != LLDB_INVALID_UID)
Daniel Malead01b2952012-11-29 21:49:15 +0000373 s->Printf(", type_uid = 0x%8.8" PRIx64, m_type_uid);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000374
375 s->EOL();
376 // Dump the root object
Greg Clayton0b76a2c2010-08-21 02:22:51 +0000377 if (m_block.BlockInfoHasBeenParsed ())
378 m_block.Dump(s, m_range.GetBaseAddress().GetFileAddress(), INT_MAX, show_context);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000379}
380
381
382void
383Function::CalculateSymbolContext(SymbolContext* sc)
384{
385 sc->function = this;
386 m_comp_unit->CalculateSymbolContext(sc);
387}
388
Greg Claytone72dfb32012-02-24 01:59:29 +0000389ModuleSP
Greg Clayton7e9b1fd2011-08-12 21:40:01 +0000390Function::CalculateSymbolContextModule ()
391{
Greg Claytone72dfb32012-02-24 01:59:29 +0000392 SectionSP section_sp (m_range.GetBaseAddress().GetSection());
393 if (section_sp)
Greg Clayton9422dd62013-03-04 21:46:16 +0000394 return section_sp->GetModule();
Jim Ingham881ec852011-10-07 22:20:35 +0000395
Greg Clayton7e9b1fd2011-08-12 21:40:01 +0000396 return this->GetCompileUnit()->GetModule();
397}
398
399CompileUnit *
400Function::CalculateSymbolContextCompileUnit ()
401{
402 return this->GetCompileUnit();
403}
404
405Function *
406Function::CalculateSymbolContextFunction ()
407{
408 return this;
409}
410
Greg Clayton44d93782014-01-27 23:43:24 +0000411lldb::DisassemblerSP
412Function::GetInstructions (const ExecutionContext &exe_ctx,
413 const char *flavor,
414 bool prefer_file_cache)
415{
416 ModuleSP module_sp (GetAddressRange().GetBaseAddress().GetModule());
417 if (module_sp)
418 {
419 const bool prefer_file_cache = false;
420 return Disassembler::DisassembleRange (module_sp->GetArchitecture(),
Ed Masted4612ad2014-04-20 13:17:36 +0000421 nullptr,
Greg Clayton44d93782014-01-27 23:43:24 +0000422 flavor,
423 exe_ctx,
424 GetAddressRange(),
425 prefer_file_cache);
426 }
427 return lldb::DisassemblerSP();
428}
429
430bool
431Function::GetDisassembly (const ExecutionContext &exe_ctx,
432 const char *flavor,
433 bool prefer_file_cache,
434 Stream &strm)
435{
436 lldb::DisassemblerSP disassembler_sp = GetInstructions (exe_ctx, flavor, prefer_file_cache);
437 if (disassembler_sp)
438 {
439 const bool show_address = true;
440 const bool show_bytes = false;
441 disassembler_sp->GetInstructionList().Dump (&strm, show_address, show_bytes, &exe_ctx);
442 return true;
443 }
444 return false;
445}
446
447
Greg Clayton7e9b1fd2011-08-12 21:40:01 +0000448//Symbol *
449//Function::CalculateSymbolContextSymbol ()
450//{
451// return // TODO: find the symbol for the function???
452//}
453
454
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000455void
456Function::DumpSymbolContext(Stream *s)
457{
458 m_comp_unit->DumpSymbolContext(s);
Daniel Malead01b2952012-11-29 21:49:15 +0000459 s->Printf(", Function{0x%8.8" PRIx64 "}", GetID());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000460}
461
462size_t
463Function::MemorySize () const
464{
Greg Clayton0b76a2c2010-08-21 02:22:51 +0000465 size_t mem_size = sizeof(Function) + m_block.MemorySize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000466 return mem_size;
467}
468
Jason Molenda6ab659a2015-07-29 00:42:47 +0000469bool
470Function::GetIsOptimized ()
471{
472 bool result = false;
473
474 // Currently optimization is only indicted by the
475 // vendor extension DW_AT_APPLE_optimized which
476 // is set on a compile unit level.
477 if (m_comp_unit)
478 {
479 result = m_comp_unit->GetIsOptimized();
480 }
481 return result;
482}
483
Enrico Granatac1f705c2015-07-06 18:28:46 +0000484ConstString
485Function::GetDisplayName () const
486{
487 if (!m_mangled)
488 return ConstString();
Greg Claytonddaf6a72015-07-08 22:32:23 +0000489 return m_mangled.GetDisplayDemangledName(GetLanguage());
Enrico Granatac1f705c2015-07-06 18:28:46 +0000490}
491
Greg Clayton99558cc42015-08-24 23:46:31 +0000492CompilerDeclContext
493Function::GetDeclContext()
Sean Callanan72e49402011-08-05 23:43:37 +0000494{
Greg Clayton99558cc42015-08-24 23:46:31 +0000495 ModuleSP module_sp = CalculateSymbolContextModule ();
496
497 if (module_sp)
498 {
499 SymbolVendor *sym_vendor = module_sp->GetSymbolVendor();
500
501 if (sym_vendor)
502 {
503 SymbolFile *sym_file = sym_vendor->GetSymbolFile();
504
505 if (sym_file)
506 return sym_file->GetDeclContextForUID (GetID());
507 }
508 }
509 return CompilerDeclContext();
Sean Callanan72e49402011-08-05 23:43:37 +0000510}
511
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000512Type*
513Function::GetType()
514{
Ed Masted4612ad2014-04-20 13:17:36 +0000515 if (m_type == nullptr)
Greg Clayton2bc22f82011-09-30 03:20:47 +0000516 {
517 SymbolContext sc;
518
519 CalculateSymbolContext (&sc);
520
521 if (!sc.module_sp)
Ed Masted4612ad2014-04-20 13:17:36 +0000522 return nullptr;
Greg Clayton2bc22f82011-09-30 03:20:47 +0000523
524 SymbolVendor *sym_vendor = sc.module_sp->GetSymbolVendor();
525
Ed Masted4612ad2014-04-20 13:17:36 +0000526 if (sym_vendor == nullptr)
527 return nullptr;
Greg Clayton2bc22f82011-09-30 03:20:47 +0000528
529 SymbolFile *sym_file = sym_vendor->GetSymbolFile();
530
Ed Masted4612ad2014-04-20 13:17:36 +0000531 if (sym_file == nullptr)
532 return nullptr;
Greg Clayton2bc22f82011-09-30 03:20:47 +0000533
Greg Clayton5cf58b92011-10-05 22:22:08 +0000534 m_type = sym_file->ResolveTypeUID(m_type_uid);
Greg Clayton2bc22f82011-09-30 03:20:47 +0000535 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000536 return m_type;
537}
538
539const Type*
540Function::GetType() const
541{
542 return m_type;
543}
544
Greg Claytona1e5dc82015-08-11 22:53:00 +0000545CompilerType
Greg Clayton99558cc42015-08-24 23:46:31 +0000546Function::GetCompilerType()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000547{
Greg Clayton57ee3062013-07-11 22:46:58 +0000548 Type *function_type = GetType();
549 if (function_type)
Greg Clayton99558cc42015-08-24 23:46:31 +0000550 return function_type->GetFullCompilerType ();
Greg Claytona1e5dc82015-08-11 22:53:00 +0000551 return CompilerType();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000552}
553
554uint32_t
555Function::GetPrologueByteSize ()
556{
557 if (m_prologue_byte_size == 0 && m_flags.IsClear(flagsCalculatedPrologueSize))
558 {
559 m_flags.Set(flagsCalculatedPrologueSize);
560 LineTable* line_table = m_comp_unit->GetLineTable ();
561 if (line_table)
562 {
Greg Clayton83b6fab2012-04-26 01:01:34 +0000563 LineEntry first_line_entry;
564 uint32_t first_line_entry_idx = UINT32_MAX;
565 if (line_table->FindLineEntryByAddress(GetAddressRange().GetBaseAddress(), first_line_entry, &first_line_entry_idx))
Greg Claytonc3b84992010-11-11 20:13:30 +0000566 {
Greg Clayton83b6fab2012-04-26 01:01:34 +0000567 // Make sure the first line entry isn't already the end of the prologue
568 addr_t prologue_end_file_addr = LLDB_INVALID_ADDRESS;
569 if (first_line_entry.is_prologue_end)
570 {
571 prologue_end_file_addr = first_line_entry.range.GetBaseAddress().GetFileAddress();
572 }
573 else
574 {
575 // Check the first few instructions and look for one that has
576 // is_prologue_end set to true.
577 const uint32_t last_line_entry_idx = first_line_entry_idx + 6;
Greg Clayton83b6fab2012-04-26 01:01:34 +0000578 for (uint32_t idx = first_line_entry_idx + 1; idx < last_line_entry_idx; ++idx)
579 {
Michael Sartaina7499c92013-07-01 19:45:50 +0000580 LineEntry line_entry;
Greg Clayton83b6fab2012-04-26 01:01:34 +0000581 if (line_table->GetLineEntryAtIndex (idx, line_entry))
582 {
583 if (line_entry.is_prologue_end)
584 {
585 prologue_end_file_addr = line_entry.range.GetBaseAddress().GetFileAddress();
586 break;
587 }
588 }
589 }
590 }
Michael Sartaina7499c92013-07-01 19:45:50 +0000591
Greg Clayton83b6fab2012-04-26 01:01:34 +0000592 // If we didn't find the end of the prologue in the line tables,
593 // then just use the end address of the first line table entry
594 if (prologue_end_file_addr == LLDB_INVALID_ADDRESS)
595 {
Michael Sartaina7499c92013-07-01 19:45:50 +0000596 // Check the first few instructions and look for one that has
597 // a line number that's different than the first entry.
598 const uint32_t last_line_entry_idx = first_line_entry_idx + 6;
599 for (uint32_t idx = first_line_entry_idx + 1; idx < last_line_entry_idx; ++idx)
600 {
601 LineEntry line_entry;
602 if (line_table->GetLineEntryAtIndex (idx, line_entry))
603 {
604 if (line_entry.line != first_line_entry.line)
605 {
606 prologue_end_file_addr = line_entry.range.GetBaseAddress().GetFileAddress();
607 break;
608 }
609 }
610 }
611
612 if (prologue_end_file_addr == LLDB_INVALID_ADDRESS)
613 {
614 prologue_end_file_addr = first_line_entry.range.GetBaseAddress().GetFileAddress() + first_line_entry.range.GetByteSize();
615 }
Greg Clayton83b6fab2012-04-26 01:01:34 +0000616 }
Greg Claytonc3b84992010-11-11 20:13:30 +0000617 const addr_t func_start_file_addr = m_range.GetBaseAddress().GetFileAddress();
Greg Clayton83b6fab2012-04-26 01:01:34 +0000618 const addr_t func_end_file_addr = func_start_file_addr + m_range.GetByteSize();
619
620 // Verify that this prologue end file address in the function's
621 // address range just to be sure
622 if (func_start_file_addr < prologue_end_file_addr && prologue_end_file_addr < func_end_file_addr)
623 {
624 m_prologue_byte_size = prologue_end_file_addr - func_start_file_addr;
625 }
Greg Claytonc3b84992010-11-11 20:13:30 +0000626 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000627 }
628 }
629 return m_prologue_byte_size;
630}
631
Greg Claytonddaf6a72015-07-08 22:32:23 +0000632lldb::LanguageType
633Function::GetLanguage() const
634{
635 if (m_comp_unit)
636 return m_comp_unit->GetLanguage();
637 else
638 return lldb::eLanguageTypeUnknown;
639}
640
641ConstString
642Function::GetName() const
643{
644 LanguageType language = lldb::eLanguageTypeUnknown;
645 if (m_comp_unit)
646 language = m_comp_unit->GetLanguage();
647 return m_mangled.GetName(language);
648}
649
650ConstString
651Function::GetNameNoArguments() const
652{
653 LanguageType language = lldb::eLanguageTypeUnknown;
654 if (m_comp_unit)
655 language = m_comp_unit->GetLanguage();
656 return m_mangled.GetName(language, Mangled::ePreferDemangledWithoutArguments);
657}
658
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000659
660