[Lldb-commits] [lldb] [lldb][RPC] Upstream lldb-rpc-gen tool (PR #138031)

Chelsea Cassanova via lldb-commits lldb-commits at lists.llvm.org
Fri May 9 12:02:51 PDT 2025


================
@@ -0,0 +1,535 @@
+//===-- RPCCommon.cpp -----------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "RPCCommon.h"
+
+#include "clang/AST/AST.h"
+#include "clang/AST/Mangle.h"
+#include "clang/Lex/Lexer.h"
+
+#include "llvm/ADT/StringExtras.h"
+#include "llvm/ADT/StringMap.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/raw_ostream.h"
+
+using namespace clang;
+
+// We intentionally do not generate some classes because they are currently
+// inconvenient, they aren't really used by most consumers, or we're not sure
+// why they exist.
+static constexpr llvm::StringRef DisallowedClasses[] = {
+    "SBCommunication",          // What is this used for?
+    "SBInputReader",            // What is this used for?
+    "SBCommandPluginInterface", // This is hard to support, we can do it if
+                                // really needed though.
+    "SBCommand", // There's nothing too difficult about this one, but many of
+                 // its methods take a SBCommandPluginInterface pointer so
+                 // there's no reason to support this.
+};
+
+// We intentionally avoid generating certain methods either because they are
+// difficult to support correctly or they aren't really used much from C++.
+// FIXME: We should be able to annotate these methods instead of maintaining a
+// list in the generator itself.
+static constexpr llvm::StringRef DisallowedMethods[] = {
+    // The threading functionality in SBHostOS is deprecated and thus we do not
+    // generate them. It would be ideal to add the annotations to the methods
+    // and then support not generating deprecated methods. However, without
+    // annotations the generator generates most things correctly. This one is
+    // problematic because it returns a pointer to an "opaque" structure
+    // (thread_t) that is not `void *`, so special casing it is more effort than
+    // it's worth.
+    "_ZN4lldb8SBHostOS10ThreadJoinEP17_opaque_pthread_tPPvPNS_7SBErrorE",
+    "_ZN4lldb8SBHostOS12ThreadCancelEP17_opaque_pthread_tPNS_7SBErrorE",
----------------
chelcassanova wrote:

@bulbazord Actually, I think this preprocessor macro has its link to the `[[deprecated]]` attribute removed in SBDefines if we're generating the SWIG bindings:
```
#if defined(SWIG) || _cplusplus < 201402L
#undef LLDB_DEPRECATED
#undef LLDB_DEPRECATED_FIXME
#define LLDB_DEPRECATED(MSG)
#define LLDB_DEPRECATED_FIXME(MSG, FIX)
#endif
```

and we're always generating the SWIG bindings when building RPC because of testing right? The definition for `LLDB_DEPRECATED` that ties it to the compiler's deprecated attribute is coming from `lldb-defines.h` and is overridden in `SBDefines.h` to just be blank (IIUC?). I think this means that when `lldb-rpc-gen` is reading any function that has `LLDB_DEPRECATED`, there's no actual `[[deprecated]]` attribute for the tool to pick up on.

I don't currently know why we don't add the deprecated attribute when generating SWIG bindings. If that's something that cannot change, is there a better way to work around this? If not then keeping the list and adding a note; as well as adding a check for the deprecated attribute anyways in `MethodIsDisallowed` would be the way to go here.

https://github.com/llvm/llvm-project/pull/138031


More information about the lldb-commits mailing list