Skip to content

[lldb] Improve identification of Dlang mangled names #93881

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions lldb/source/Core/Mangled.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "lldb/Utility/Stream.h"
#include "lldb/lldb-enumerations.h"

#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Demangle/Demangle.h"
#include "llvm/Support/Compiler.h"
Expand Down Expand Up @@ -48,8 +49,14 @@ Mangled::ManglingScheme Mangled::GetManglingScheme(llvm::StringRef const name) {
if (name.starts_with("_R"))
return Mangled::eManglingSchemeRustV0;

if (name.starts_with("_D"))
return Mangled::eManglingSchemeD;
if (name.starts_with("_D")) {
// A dlang mangled name begins with `_D`, followed by a numeric length.
// See `SymbolName` and `LName` in
// https://dlang.org/spec/abi.html#name_mangling
llvm::StringRef buf = name.drop_front(2);
if (!buf.empty() && llvm::isDigit(buf.front()))
return Mangled::eManglingSchemeD;
}

if (name.starts_with("_Z"))
return Mangled::eManglingSchemeItanium;
Expand Down
4 changes: 4 additions & 0 deletions lldb/test/API/lang/c/non-mangled/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
C_SOURCES := main.c
CFLAGS_EXTRAS := -std=c99

include Makefile.rules
15 changes: 15 additions & 0 deletions lldb/test/API/lang/c/non-mangled/TestCNonMangled.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import lldbsuite.test.lldbutil as lldbutil
from lldbsuite.test.lldbtest import *


class TestCase(TestBase):
def test_functions_having_dlang_mangling_prefix(self):
"""
Ensure C functions with a '_D' prefix alone are not mistakenly treated
as a Dlang mangled name. A proper Dlang mangling will have digits
immediately following the '_D' prefix.
"""
self.build()
_, _, thread, _ = lldbutil.run_to_name_breakpoint(self, "_Dfunction")
symbol = thread.frame[0].symbol
self.assertEqual(symbol.GetDisplayName(), "_Dfunction")
8 changes: 8 additions & 0 deletions lldb/test/API/lang/c/non-mangled/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#include <stdio.h>

void _Dfunction() {}

int main() {
_Dfunction();
return 0;
}
Loading