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