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