1 //===-- Function.cpp ------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #include "lldb/Symbol/Function.h"
10 #include "lldb/Core/Disassembler.h"
11 #include "lldb/Core/Module.h"
12 #include "lldb/Core/ModuleList.h"
13 #include "lldb/Core/Section.h"
14 #include "lldb/Host/Host.h"
15 #include "lldb/Symbol/CompileUnit.h"
16 #include "lldb/Symbol/CompilerType.h"
17 #include "lldb/Symbol/LineTable.h"
18 #include "lldb/Symbol/SymbolFile.h"
19 #include "lldb/Target/Language.h"
20 #include "lldb/Target/Target.h"
21 #include "lldb/Utility/Log.h"
22 #include "llvm/Support/Casting.h"
23 
24 using namespace lldb;
25 using namespace lldb_private;
26 
27 // Basic function information is contained in the FunctionInfo class. It is
28 // designed to contain the name, linkage name, and declaration location.
29 FunctionInfo::FunctionInfo(const char *name, const Declaration *decl_ptr)
30     : m_name(name), m_declaration(decl_ptr) {}
31 
32 FunctionInfo::FunctionInfo(ConstString name, const Declaration *decl_ptr)
33     : m_name(name), m_declaration(decl_ptr) {}
34 
35 FunctionInfo::~FunctionInfo() {}
36 
37 void FunctionInfo::Dump(Stream *s, bool show_fullpaths) const {
38   if (m_name)
39     *s << ", name = \"" << m_name << "\"";
40   m_declaration.Dump(s, show_fullpaths);
41 }
42 
43 int FunctionInfo::Compare(const FunctionInfo &a, const FunctionInfo &b) {
44   int result = ConstString::Compare(a.GetName(), b.GetName());
45   if (result)
46     return result;
47 
48   return Declaration::Compare(a.m_declaration, b.m_declaration);
49 }
50 
51 Declaration &FunctionInfo::GetDeclaration() { return m_declaration; }
52 
53 const Declaration &FunctionInfo::GetDeclaration() const {
54   return m_declaration;
55 }
56 
57 ConstString FunctionInfo::GetName() const { return m_name; }
58 
59 size_t FunctionInfo::MemorySize() const {
60   return m_name.MemorySize() + m_declaration.MemorySize();
61 }
62 
63 InlineFunctionInfo::InlineFunctionInfo(const char *name,
64                                        llvm::StringRef mangled,
65                                        const Declaration *decl_ptr,
66                                        const Declaration *call_decl_ptr)
67     : FunctionInfo(name, decl_ptr), m_mangled(mangled),
68       m_call_decl(call_decl_ptr) {}
69 
70 InlineFunctionInfo::InlineFunctionInfo(ConstString name,
71                                        const Mangled &mangled,
72                                        const Declaration *decl_ptr,
73                                        const Declaration *call_decl_ptr)
74     : FunctionInfo(name, decl_ptr), m_mangled(mangled),
75       m_call_decl(call_decl_ptr) {}
76 
77 InlineFunctionInfo::~InlineFunctionInfo() {}
78 
79 void InlineFunctionInfo::Dump(Stream *s, bool show_fullpaths) const {
80   FunctionInfo::Dump(s, show_fullpaths);
81   if (m_mangled)
82     m_mangled.Dump(s);
83 }
84 
85 void InlineFunctionInfo::DumpStopContext(Stream *s) const {
86   //    s->Indent("[inlined] ");
87   s->Indent();
88   if (m_mangled)
89     s->PutCString(m_mangled.GetName().AsCString());
90   else
91     s->PutCString(m_name.AsCString());
92 }
93 
94 ConstString InlineFunctionInfo::GetName() const {
95   if (m_mangled)
96     return m_mangled.GetName();
97   return m_name;
98 }
99 
100 ConstString InlineFunctionInfo::GetDisplayName() const {
101   if (m_mangled)
102     return m_mangled.GetDisplayDemangledName();
103   return m_name;
104 }
105 
106 Declaration &InlineFunctionInfo::GetCallSite() { return m_call_decl; }
107 
108 const Declaration &InlineFunctionInfo::GetCallSite() const {
109   return m_call_decl;
110 }
111 
112 Mangled &InlineFunctionInfo::GetMangled() { return m_mangled; }
113 
114 const Mangled &InlineFunctionInfo::GetMangled() const { return m_mangled; }
115 
116 size_t InlineFunctionInfo::MemorySize() const {
117   return FunctionInfo::MemorySize() + m_mangled.MemorySize();
118 }
119 
120 /// @name Call site related structures
121 /// @{
122 
123 lldb::addr_t CallEdge::GetLoadAddress(lldb::addr_t unresolved_pc,
124                                       Function &caller, Target &target) {
125   Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_STEP));
126 
127   const Address &caller_start_addr = caller.GetAddressRange().GetBaseAddress();
128 
129   ModuleSP caller_module_sp = caller_start_addr.GetModule();
130   if (!caller_module_sp) {
131     LLDB_LOG(log, "GetLoadAddress: cannot get Module for caller");
132     return LLDB_INVALID_ADDRESS;
133   }
134 
135   SectionList *section_list = caller_module_sp->GetSectionList();
136   if (!section_list) {
137     LLDB_LOG(log, "GetLoadAddress: cannot get SectionList for Module");
138     return LLDB_INVALID_ADDRESS;
139   }
140 
141   Address the_addr = Address(unresolved_pc, section_list);
142   lldb::addr_t load_addr = the_addr.GetLoadAddress(&target);
143   return load_addr;
144 }
145 
146 lldb::addr_t CallEdge::GetReturnPCAddress(Function &caller,
147                                           Target &target) const {
148   return GetLoadAddress(return_pc, caller, target);
149 }
150 
151 lldb::addr_t CallEdge::GetCallInstPC(Function &caller, Target &target) const {
152   return GetLoadAddress(call_inst_pc, caller, target);
153 }
154 
155 void DirectCallEdge::ParseSymbolFileAndResolve(ModuleList &images) {
156   if (resolved)
157     return;
158 
159   Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_STEP));
160   LLDB_LOG(log, "DirectCallEdge: Lazily parsing the call graph for {0}",
161            lazy_callee.symbol_name);
162 
163   auto resolve_lazy_callee = [&]() -> Function * {
164     ConstString callee_name{lazy_callee.symbol_name};
165     SymbolContextList sc_list;
166     images.FindFunctionSymbols(callee_name, eFunctionNameTypeAuto, sc_list);
167     size_t num_matches = sc_list.GetSize();
168     if (num_matches == 0 || !sc_list[0].symbol) {
169       LLDB_LOG(log,
170                "DirectCallEdge: Found no symbols for {0}, cannot resolve it",
171                callee_name);
172       return nullptr;
173     }
174     Address callee_addr = sc_list[0].symbol->GetAddress();
175     if (!callee_addr.IsValid()) {
176       LLDB_LOG(log, "DirectCallEdge: Invalid symbol address");
177       return nullptr;
178     }
179     Function *f = callee_addr.CalculateSymbolContextFunction();
180     if (!f) {
181       LLDB_LOG(log, "DirectCallEdge: Could not find complete function");
182       return nullptr;
183     }
184     return f;
185   };
186   lazy_callee.def = resolve_lazy_callee();
187   resolved = true;
188 }
189 
190 Function *DirectCallEdge::GetCallee(ModuleList &images, ExecutionContext &) {
191   ParseSymbolFileAndResolve(images);
192   assert(resolved && "Did not resolve lazy callee");
193   return lazy_callee.def;
194 }
195 
196 Function *IndirectCallEdge::GetCallee(ModuleList &images,
197                                       ExecutionContext &exe_ctx) {
198   Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_STEP));
199   Status error;
200   Value callee_addr_val;
201   if (!call_target.Evaluate(&exe_ctx, exe_ctx.GetRegisterContext(),
202                             /*loclist_base_addr=*/LLDB_INVALID_ADDRESS,
203                             /*initial_value_ptr=*/nullptr,
204                             /*object_address_ptr=*/nullptr, callee_addr_val,
205                             &error)) {
206     LLDB_LOGF(log, "IndirectCallEdge: Could not evaluate expression: %s",
207               error.AsCString());
208     return nullptr;
209   }
210 
211   addr_t raw_addr = callee_addr_val.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
212   if (raw_addr == LLDB_INVALID_ADDRESS) {
213     LLDB_LOG(log, "IndirectCallEdge: Could not extract address from scalar");
214     return nullptr;
215   }
216 
217   Address callee_addr;
218   if (!exe_ctx.GetTargetPtr()->ResolveLoadAddress(raw_addr, callee_addr)) {
219     LLDB_LOG(log, "IndirectCallEdge: Could not resolve callee's load address");
220     return nullptr;
221   }
222 
223   Function *f = callee_addr.CalculateSymbolContextFunction();
224   if (!f) {
225     LLDB_LOG(log, "IndirectCallEdge: Could not find complete function");
226     return nullptr;
227   }
228 
229   return f;
230 }
231 
232 /// @}
233 
234 //
235 Function::Function(CompileUnit *comp_unit, lldb::user_id_t func_uid,
236                    lldb::user_id_t type_uid, const Mangled &mangled, Type *type,
237                    const AddressRange &range)
238     : UserID(func_uid), m_comp_unit(comp_unit), m_type_uid(type_uid),
239       m_type(type), m_mangled(mangled), m_block(func_uid), m_range(range),
240       m_frame_base(), m_flags(), m_prologue_byte_size(0) {
241   m_block.SetParentScope(this);
242   assert(comp_unit != nullptr);
243 }
244 
245 Function::~Function() {}
246 
247 void Function::GetStartLineSourceInfo(FileSpec &source_file,
248                                       uint32_t &line_no) {
249   line_no = 0;
250   source_file.Clear();
251 
252   if (m_comp_unit == nullptr)
253     return;
254 
255   // Initialize m_type if it hasn't been initialized already
256   GetType();
257 
258   if (m_type != nullptr && m_type->GetDeclaration().GetLine() != 0) {
259     source_file = m_type->GetDeclaration().GetFile();
260     line_no = m_type->GetDeclaration().GetLine();
261   } else {
262     LineTable *line_table = m_comp_unit->GetLineTable();
263     if (line_table == nullptr)
264       return;
265 
266     LineEntry line_entry;
267     if (line_table->FindLineEntryByAddress(GetAddressRange().GetBaseAddress(),
268                                            line_entry, nullptr)) {
269       line_no = line_entry.line;
270       source_file = line_entry.file;
271     }
272   }
273 }
274 
275 void Function::GetEndLineSourceInfo(FileSpec &source_file, uint32_t &line_no) {
276   line_no = 0;
277   source_file.Clear();
278 
279   // The -1 is kind of cheesy, but I want to get the last line entry for the
280   // given function, not the first entry of the next.
281   Address scratch_addr(GetAddressRange().GetBaseAddress());
282   scratch_addr.SetOffset(scratch_addr.GetOffset() +
283                          GetAddressRange().GetByteSize() - 1);
284 
285   LineTable *line_table = m_comp_unit->GetLineTable();
286   if (line_table == nullptr)
287     return;
288 
289   LineEntry line_entry;
290   if (line_table->FindLineEntryByAddress(scratch_addr, line_entry, nullptr)) {
291     line_no = line_entry.line;
292     source_file = line_entry.file;
293   }
294 }
295 
296 llvm::ArrayRef<std::unique_ptr<CallEdge>> Function::GetCallEdges() {
297   if (m_call_edges_resolved)
298     return m_call_edges;
299 
300   Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_STEP));
301   LLDB_LOG(log, "GetCallEdges: Attempting to parse call site info for {0}",
302            GetDisplayName());
303 
304   m_call_edges_resolved = true;
305 
306   // Find the SymbolFile which provided this function's definition.
307   Block &block = GetBlock(/*can_create*/true);
308   SymbolFile *sym_file = block.GetSymbolFile();
309   if (!sym_file)
310     return llvm::None;
311 
312   // Lazily read call site information from the SymbolFile.
313   m_call_edges = sym_file->ParseCallEdgesInFunction(GetID());
314 
315   // Sort the call edges to speed up return_pc lookups.
316   llvm::sort(m_call_edges.begin(), m_call_edges.end(),
317              [](const std::unique_ptr<CallEdge> &LHS,
318                 const std::unique_ptr<CallEdge> &RHS) {
319                return LHS->GetUnresolvedReturnPCAddress() <
320                       RHS->GetUnresolvedReturnPCAddress();
321              });
322 
323   return m_call_edges;
324 }
325 
326 llvm::ArrayRef<std::unique_ptr<CallEdge>> Function::GetTailCallingEdges() {
327   // Call edges are sorted by return PC, and tail calling edges have invalid
328   // return PCs. Find them at the end of the list.
329   return GetCallEdges().drop_until([](const std::unique_ptr<CallEdge> &edge) {
330     return edge->GetUnresolvedReturnPCAddress() == LLDB_INVALID_ADDRESS;
331   });
332 }
333 
334 CallEdge *Function::GetCallEdgeForReturnAddress(addr_t return_pc,
335                                                 Target &target) {
336   auto edges = GetCallEdges();
337   auto edge_it =
338       std::lower_bound(edges.begin(), edges.end(), return_pc,
339                        [&](const std::unique_ptr<CallEdge> &edge, addr_t pc) {
340                          return edge->GetReturnPCAddress(*this, target) < pc;
341                        });
342   if (edge_it == edges.end() ||
343       edge_it->get()->GetReturnPCAddress(*this, target) != return_pc)
344     return nullptr;
345   return &const_cast<CallEdge &>(*edge_it->get());
346 }
347 
348 Block &Function::GetBlock(bool can_create) {
349   if (!m_block.BlockInfoHasBeenParsed() && can_create) {
350     ModuleSP module_sp = CalculateSymbolContextModule();
351     if (module_sp) {
352       module_sp->GetSymbolFile()->ParseBlocksRecursive(*this);
353     } else {
354       Host::SystemLog(Host::eSystemLogError,
355                       "error: unable to find module "
356                       "shared pointer for function '%s' "
357                       "in %s\n",
358                       GetName().GetCString(),
359                       m_comp_unit->GetPrimaryFile().GetPath().c_str());
360     }
361     m_block.SetBlockInfoHasBeenParsed(true, true);
362   }
363   return m_block;
364 }
365 
366 CompileUnit *Function::GetCompileUnit() { return m_comp_unit; }
367 
368 const CompileUnit *Function::GetCompileUnit() const { return m_comp_unit; }
369 
370 void Function::GetDescription(Stream *s, lldb::DescriptionLevel level,
371                               Target *target) {
372   ConstString name = GetName();
373   ConstString mangled = m_mangled.GetMangledName();
374 
375   *s << "id = " << (const UserID &)*this;
376   if (name)
377     *s << ", name = \"" << name.GetCString() << '"';
378   if (mangled)
379     *s << ", mangled = \"" << mangled.GetCString() << '"';
380   *s << ", range = ";
381   Address::DumpStyle fallback_style;
382   if (level == eDescriptionLevelVerbose)
383     fallback_style = Address::DumpStyleModuleWithFileAddress;
384   else
385     fallback_style = Address::DumpStyleFileAddress;
386   GetAddressRange().Dump(s, target, Address::DumpStyleLoadAddress,
387                          fallback_style);
388 }
389 
390 void Function::Dump(Stream *s, bool show_context) const {
391   s->Printf("%p: ", static_cast<const void *>(this));
392   s->Indent();
393   *s << "Function" << static_cast<const UserID &>(*this);
394 
395   m_mangled.Dump(s);
396 
397   if (m_type)
398     s->Printf(", type = %p", static_cast<void *>(m_type));
399   else if (m_type_uid != LLDB_INVALID_UID)
400     s->Printf(", type_uid = 0x%8.8" PRIx64, m_type_uid);
401 
402   s->EOL();
403   // Dump the root object
404   if (m_block.BlockInfoHasBeenParsed())
405     m_block.Dump(s, m_range.GetBaseAddress().GetFileAddress(), INT_MAX,
406                  show_context);
407 }
408 
409 void Function::CalculateSymbolContext(SymbolContext *sc) {
410   sc->function = this;
411   m_comp_unit->CalculateSymbolContext(sc);
412 }
413 
414 ModuleSP Function::CalculateSymbolContextModule() {
415   SectionSP section_sp(m_range.GetBaseAddress().GetSection());
416   if (section_sp)
417     return section_sp->GetModule();
418 
419   return this->GetCompileUnit()->GetModule();
420 }
421 
422 CompileUnit *Function::CalculateSymbolContextCompileUnit() {
423   return this->GetCompileUnit();
424 }
425 
426 Function *Function::CalculateSymbolContextFunction() { return this; }
427 
428 lldb::DisassemblerSP Function::GetInstructions(const ExecutionContext &exe_ctx,
429                                                const char *flavor,
430                                                bool prefer_file_cache) {
431   ModuleSP module_sp(GetAddressRange().GetBaseAddress().GetModule());
432   if (module_sp && exe_ctx.HasTargetScope()) {
433     const bool prefer_file_cache = false;
434     return Disassembler::DisassembleRange(module_sp->GetArchitecture(), nullptr,
435                                           flavor, exe_ctx.GetTargetRef(),
436                                           GetAddressRange(), prefer_file_cache);
437   }
438   return lldb::DisassemblerSP();
439 }
440 
441 bool Function::GetDisassembly(const ExecutionContext &exe_ctx,
442                               const char *flavor, bool prefer_file_cache,
443                               Stream &strm) {
444   lldb::DisassemblerSP disassembler_sp =
445       GetInstructions(exe_ctx, flavor, prefer_file_cache);
446   if (disassembler_sp) {
447     const bool show_address = true;
448     const bool show_bytes = false;
449     disassembler_sp->GetInstructionList().Dump(&strm, show_address, show_bytes,
450                                                &exe_ctx);
451     return true;
452   }
453   return false;
454 }
455 
456 // Symbol *
457 // Function::CalculateSymbolContextSymbol ()
458 //{
459 //    return // TODO: find the symbol for the function???
460 //}
461 
462 void Function::DumpSymbolContext(Stream *s) {
463   m_comp_unit->DumpSymbolContext(s);
464   s->Printf(", Function{0x%8.8" PRIx64 "}", GetID());
465 }
466 
467 size_t Function::MemorySize() const {
468   size_t mem_size = sizeof(Function) + m_block.MemorySize();
469   return mem_size;
470 }
471 
472 bool Function::GetIsOptimized() {
473   bool result = false;
474 
475   // Currently optimization is only indicted by the vendor extension
476   // DW_AT_APPLE_optimized which is set on a compile unit level.
477   if (m_comp_unit) {
478     result = m_comp_unit->GetIsOptimized();
479   }
480   return result;
481 }
482 
483 bool Function::IsTopLevelFunction() {
484   bool result = false;
485 
486   if (Language *language = Language::FindPlugin(GetLanguage()))
487     result = language->IsTopLevelFunction(*this);
488 
489   return result;
490 }
491 
492 ConstString Function::GetDisplayName() const {
493   return m_mangled.GetDisplayDemangledName();
494 }
495 
496 CompilerDeclContext Function::GetDeclContext() {
497   ModuleSP module_sp = CalculateSymbolContextModule();
498 
499   if (module_sp) {
500     if (SymbolFile *sym_file = module_sp->GetSymbolFile())
501       return sym_file->GetDeclContextForUID(GetID());
502   }
503   return CompilerDeclContext();
504 }
505 
506 Type *Function::GetType() {
507   if (m_type == nullptr) {
508     SymbolContext sc;
509 
510     CalculateSymbolContext(&sc);
511 
512     if (!sc.module_sp)
513       return nullptr;
514 
515     SymbolFile *sym_file = sc.module_sp->GetSymbolFile();
516 
517     if (sym_file == nullptr)
518       return nullptr;
519 
520     m_type = sym_file->ResolveTypeUID(m_type_uid);
521   }
522   return m_type;
523 }
524 
525 const Type *Function::GetType() const { return m_type; }
526 
527 CompilerType Function::GetCompilerType() {
528   Type *function_type = GetType();
529   if (function_type)
530     return function_type->GetFullCompilerType();
531   return CompilerType();
532 }
533 
534 uint32_t Function::GetPrologueByteSize() {
535   if (m_prologue_byte_size == 0 &&
536       m_flags.IsClear(flagsCalculatedPrologueSize)) {
537     m_flags.Set(flagsCalculatedPrologueSize);
538     LineTable *line_table = m_comp_unit->GetLineTable();
539     uint32_t prologue_end_line_idx = 0;
540 
541     if (line_table) {
542       LineEntry first_line_entry;
543       uint32_t first_line_entry_idx = UINT32_MAX;
544       if (line_table->FindLineEntryByAddress(GetAddressRange().GetBaseAddress(),
545                                              first_line_entry,
546                                              &first_line_entry_idx)) {
547         // Make sure the first line entry isn't already the end of the prologue
548         addr_t prologue_end_file_addr = LLDB_INVALID_ADDRESS;
549         addr_t line_zero_end_file_addr = LLDB_INVALID_ADDRESS;
550 
551         if (first_line_entry.is_prologue_end) {
552           prologue_end_file_addr =
553               first_line_entry.range.GetBaseAddress().GetFileAddress();
554           prologue_end_line_idx = first_line_entry_idx;
555         } else {
556           // Check the first few instructions and look for one that has
557           // is_prologue_end set to true.
558           const uint32_t last_line_entry_idx = first_line_entry_idx + 6;
559           for (uint32_t idx = first_line_entry_idx + 1;
560                idx < last_line_entry_idx; ++idx) {
561             LineEntry line_entry;
562             if (line_table->GetLineEntryAtIndex(idx, line_entry)) {
563               if (line_entry.is_prologue_end) {
564                 prologue_end_file_addr =
565                     line_entry.range.GetBaseAddress().GetFileAddress();
566                 prologue_end_line_idx = idx;
567                 break;
568               }
569             }
570           }
571         }
572 
573         // If we didn't find the end of the prologue in the line tables, then
574         // just use the end address of the first line table entry
575         if (prologue_end_file_addr == LLDB_INVALID_ADDRESS) {
576           // Check the first few instructions and look for one that has a line
577           // number that's different than the first entry.
578           uint32_t last_line_entry_idx = first_line_entry_idx + 6;
579           for (uint32_t idx = first_line_entry_idx + 1;
580                idx < last_line_entry_idx; ++idx) {
581             LineEntry line_entry;
582             if (line_table->GetLineEntryAtIndex(idx, line_entry)) {
583               if (line_entry.line != first_line_entry.line) {
584                 prologue_end_file_addr =
585                     line_entry.range.GetBaseAddress().GetFileAddress();
586                 prologue_end_line_idx = idx;
587                 break;
588               }
589             }
590           }
591 
592           if (prologue_end_file_addr == LLDB_INVALID_ADDRESS) {
593             prologue_end_file_addr =
594                 first_line_entry.range.GetBaseAddress().GetFileAddress() +
595                 first_line_entry.range.GetByteSize();
596             prologue_end_line_idx = first_line_entry_idx;
597           }
598         }
599 
600         const addr_t func_start_file_addr =
601             m_range.GetBaseAddress().GetFileAddress();
602         const addr_t func_end_file_addr =
603             func_start_file_addr + m_range.GetByteSize();
604 
605         // Now calculate the offset to pass the subsequent line 0 entries.
606         uint32_t first_non_zero_line = prologue_end_line_idx;
607         while (true) {
608           LineEntry line_entry;
609           if (line_table->GetLineEntryAtIndex(first_non_zero_line,
610                                               line_entry)) {
611             if (line_entry.line != 0)
612               break;
613           }
614           if (line_entry.range.GetBaseAddress().GetFileAddress() >=
615               func_end_file_addr)
616             break;
617 
618           first_non_zero_line++;
619         }
620 
621         if (first_non_zero_line > prologue_end_line_idx) {
622           LineEntry first_non_zero_entry;
623           if (line_table->GetLineEntryAtIndex(first_non_zero_line,
624                                               first_non_zero_entry)) {
625             line_zero_end_file_addr =
626                 first_non_zero_entry.range.GetBaseAddress().GetFileAddress();
627           }
628         }
629 
630         // Verify that this prologue end file address in the function's address
631         // range just to be sure
632         if (func_start_file_addr < prologue_end_file_addr &&
633             prologue_end_file_addr < func_end_file_addr) {
634           m_prologue_byte_size = prologue_end_file_addr - func_start_file_addr;
635         }
636 
637         if (prologue_end_file_addr < line_zero_end_file_addr &&
638             line_zero_end_file_addr < func_end_file_addr) {
639           m_prologue_byte_size +=
640               line_zero_end_file_addr - prologue_end_file_addr;
641         }
642       }
643     }
644   }
645 
646   return m_prologue_byte_size;
647 }
648 
649 lldb::LanguageType Function::GetLanguage() const {
650   lldb::LanguageType lang = m_mangled.GuessLanguage();
651   if (lang != lldb::eLanguageTypeUnknown)
652     return lang;
653 
654   if (m_comp_unit)
655     return m_comp_unit->GetLanguage();
656 
657   return lldb::eLanguageTypeUnknown;
658 }
659 
660 ConstString Function::GetName() const {
661   return m_mangled.GetName();
662 }
663 
664 ConstString Function::GetNameNoArguments() const {
665   return m_mangled.GetName(Mangled::ePreferDemangledWithoutArguments);
666 }
667