[Lldb-commits] [lldb] [debugserver][NFC] Make helper functions have internal linkage (PR #162307)

via lldb-commits lldb-commits at lists.llvm.org
Tue Oct 7 08:46:40 PDT 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-lldb

Author: Felipe de Azevedo Piovezan (felipepiovezan)

<details>
<summary>Changes</summary>

This also allowed deleting unreachable code.

---
Full diff: https://github.com/llvm/llvm-project/pull/162307.diff


1 Files Affected:

- (modified) lldb/tools/debugserver/source/RNBRemote.cpp (+40-73) 


``````````diff
diff --git a/lldb/tools/debugserver/source/RNBRemote.cpp b/lldb/tools/debugserver/source/RNBRemote.cpp
index 434e9cfa40fb4..9d8413c635dd8 100644
--- a/lldb/tools/debugserver/source/RNBRemote.cpp
+++ b/lldb/tools/debugserver/source/RNBRemote.cpp
@@ -93,7 +93,6 @@ static const std::string JSON_ASYNC_TYPE_KEY_NAME("type");
   std::setfill(' ') << std::setw((iword_idx)) << ""
 #define INDENT_WITH_TABS(iword_idx)                                            \
   std::setfill('\t') << std::setw((iword_idx)) << ""
-// Class to handle communications via gdb remote protocol.
 
 // Prototypes
 
@@ -139,16 +138,16 @@ static std::string decode_hex_ascii_string(const char *p,
   return arg;
 }
 
-uint64_t decode_uint64(const char *p, int base, char **end = nullptr,
-                       uint64_t fail_value = 0) {
+static uint64_t decode_uint64(const char *p, int base, char **end = nullptr,
+                              uint64_t fail_value = 0) {
   nub_addr_t addr = strtoull(p, end, 16);
   if (addr == 0 && errno != 0)
     return fail_value;
   return addr;
 }
 
-void append_hex_value(std::ostream &ostrm, const void *buf, size_t buf_size,
-                      bool swap) {
+static void append_hex_value(std::ostream &ostrm, const void *buf,
+                             size_t buf_size, bool swap) {
   int i;
   const uint8_t *p = (const uint8_t *)buf;
   if (swap) {
@@ -160,7 +159,7 @@ void append_hex_value(std::ostream &ostrm, const void *buf, size_t buf_size,
   }
 }
 
-std::string cstring_to_asciihex_string(const char *str) {
+static std::string cstring_to_asciihex_string(const char *str) {
   std::string hex_str;
   hex_str.reserve(strlen(str) * 2);
   while (str && *str) {
@@ -172,7 +171,8 @@ std::string cstring_to_asciihex_string(const char *str) {
   return hex_str;
 }
 
-void append_hexified_string(std::ostream &ostrm, const std::string &string) {
+static void append_hexified_string(std::ostream &ostrm,
+                                   const std::string &string) {
   size_t string_size = string.size();
   const char *string_buf = string.c_str();
   for (size_t i = 0; i < string_size; i++) {
@@ -1027,8 +1027,6 @@ rnb_err_t RNBRemote::HandleAsyncPacket(PacketEnum *type) {
 rnb_err_t RNBRemote::HandleReceivedPacket(PacketEnum *type) {
   static DNBTimer g_packetTimer(true);
 
-  //  DNBLogThreadedIf (LOG_RNB_REMOTE, "%8u RNBRemote::%s",
-  //  (uint32_t)m_comm.Timer().ElapsedMicroSeconds(true), __FUNCTION__);
   rnb_err_t err = rnb_err;
   std::string packet_data;
   RNBRemote::Packet packet_info;
@@ -1284,8 +1282,7 @@ static cpu_type_t best_guess_cpu_type() {
  LEN is the number of bytes to be processed.  If a character is escaped,
  it is 2 characters for LEN.  A LEN of -1 means decode-until-nul-byte
  (end of string).  */
-
-std::vector<uint8_t> decode_binary_data(const char *str, size_t len) {
+static std::vector<uint8_t> decode_binary_data(const char *str, size_t len) {
   std::vector<uint8_t> bytes;
   if (len == 0) {
     return bytes;
@@ -1327,8 +1324,7 @@ static std::string binary_encode_string(const std::string &s) {
 // If the value side of a key-value pair in JSON is a string,
 // and that string has a " character in it, the " character must
 // be escaped.
-
-std::string json_string_quote_metachars(const std::string &s) {
+static std::string json_string_quote_metachars(const std::string &s) {
   if (s.find('"') == std::string::npos)
     return s;
 
@@ -1462,15 +1458,6 @@ bool RNBRemote::InitializeRegisters(bool force) {
       }
     }
 
-    //        for (auto &reg_entry: g_dynamic_register_map)
-    //        {
-    //            DNBLogThreaded("%4i: size = %3u, pseudo = %i, name = %s",
-    //                           reg_entry.offset,
-    //                           reg_entry.nub_info.size,
-    //                           reg_entry.nub_info.value_regs != NULL,
-    //                           reg_entry.nub_info.name);
-    //        }
-
     g_reg_entries = g_dynamic_register_map.data();
     g_num_reg_entries = g_dynamic_register_map.size();
   }
@@ -1719,7 +1706,7 @@ rnb_err_t RNBRemote::HandlePacket_qThreadExtraInfo(const char *p) {
   return SendPacket("");
 }
 
-const char *k_space_delimiters = " \t";
+static const char *k_space_delimiters = " \t";
 static void skip_spaces(std::string &line) {
   if (!line.empty()) {
     size_t space_pos = line.find_first_not_of(k_space_delimiters);
@@ -2024,7 +2011,7 @@ rnb_err_t RNBRemote::HandlePacket_qRegisterInfo(const char *p) {
  QSetLogging:bitmask=LOG_ALL;mode=asl;
  */
 
-rnb_err_t set_logging(const char *p) {
+static rnb_err_t set_logging(const char *p) {
   int bitmask = 0;
   while (p && *p != '\0') {
     if (strncmp(p, "bitmask=", sizeof("bitmask=") - 1) == 0) {
@@ -2568,11 +2555,10 @@ rnb_err_t RNBRemote::HandlePacket_QSetProcessEvent(const char *p) {
 
 // If a fail_value is provided, a correct-length reply is always provided,
 // even if the register cannot be read right now on this thread.
-bool register_value_in_hex_fixed_width(std::ostream &ostrm, nub_process_t pid,
-                                       nub_thread_t tid,
-                                       const register_map_entry_t *reg,
-                                       const DNBRegisterValue *reg_value_ptr,
-                                       std::optional<uint8_t> fail_value) {
+static bool register_value_in_hex_fixed_width(
+    std::ostream &ostrm, nub_process_t pid, nub_thread_t tid,
+    const register_map_entry_t *reg, const DNBRegisterValue *reg_value_ptr,
+    std::optional<uint8_t> fail_value) {
   if (reg != NULL) {
     std::unique_ptr<DNBRegisterValue> reg_value =
         std::make_unique<DNBRegisterValue>();
@@ -2599,7 +2585,7 @@ bool register_value_in_hex_fixed_width(std::ostream &ostrm, nub_process_t pid,
   return false;
 }
 
-void debugserver_regnum_with_fixed_width_hex_register_value(
+static void debugserver_regnum_with_fixed_width_hex_register_value(
     std::ostream &ostrm, nub_process_t pid, nub_thread_t tid,
     const register_map_entry_t *reg, const DNBRegisterValue *reg_value_ptr,
     std::optional<uint8_t> fail_value) {
@@ -4902,8 +4888,8 @@ rnb_err_t RNBRemote::HandlePacket_qHostInfo(const char *p) {
   return SendPacket(strm.str());
 }
 
-void XMLElementStart(std::ostringstream &s, uint32_t indent, const char *name,
-                     bool has_attributes) {
+static void XMLElementStart(std::ostringstream &s, uint32_t indent,
+                            const char *name, bool has_attributes) {
   if (indent)
     s << INDENT_WITH_SPACES(indent);
   s << '<' << name;
@@ -4911,43 +4897,22 @@ void XMLElementStart(std::ostringstream &s, uint32_t indent, const char *name,
     s << '>' << std::endl;
 }
 
-void XMLElementStartEndAttributes(std::ostringstream &s, bool empty) {
+static void XMLElementStartEndAttributes(std::ostringstream &s, bool empty) {
   if (empty)
     s << '/';
   s << '>' << std::endl;
 }
 
-void XMLElementEnd(std::ostringstream &s, uint32_t indent, const char *name) {
+static void XMLElementEnd(std::ostringstream &s, uint32_t indent,
+                          const char *name) {
   if (indent)
     s << INDENT_WITH_SPACES(indent);
   s << '<' << '/' << name << '>' << std::endl;
 }
 
-void XMLElementWithStringValue(std::ostringstream &s, uint32_t indent,
-                               const char *name, const char *value,
-                               bool close = true) {
-  if (value) {
-    if (indent)
-      s << INDENT_WITH_SPACES(indent);
-    s << '<' << name << '>' << value;
-    if (close)
-      XMLElementEnd(s, 0, name);
-  }
-}
-
-void XMLElementWithUnsignedValue(std::ostringstream &s, uint32_t indent,
-                                 const char *name, uint64_t value,
-                                 bool close = true) {
-  if (indent)
-    s << INDENT_WITH_SPACES(indent);
-
-  s << '<' << name << '>' << DECIMAL << value;
-  if (close)
-    XMLElementEnd(s, 0, name);
-}
-
-void XMLAttributeString(std::ostringstream &s, const char *name,
-                        const char *value, const char *default_value = NULL) {
+static void XMLAttributeString(std::ostringstream &s, const char *name,
+                               const char *value,
+                               const char *default_value = NULL) {
   if (value) {
     if (default_value && strcmp(value, default_value) == 0)
       return; // No need to emit the attribute because it matches the default
@@ -4956,15 +4921,16 @@ void XMLAttributeString(std::ostringstream &s, const char *name,
   }
 }
 
-void XMLAttributeUnsignedDecimal(std::ostringstream &s, const char *name,
-                                 uint64_t value) {
+static void XMLAttributeUnsignedDecimal(std::ostringstream &s, const char *name,
+                                        uint64_t value) {
   s << ' ' << name << "=\"" << DECIMAL << value << "\"";
 }
 
-void GenerateTargetXMLRegister(std::ostringstream &s, const uint32_t reg_num,
-                               nub_size_t num_reg_sets,
-                               const DNBRegisterSetInfo *reg_set_info,
-                               const register_map_entry_t &reg) {
+static void GenerateTargetXMLRegister(std::ostringstream &s,
+                                      const uint32_t reg_num,
+                                      nub_size_t num_reg_sets,
+                                      const DNBRegisterSetInfo *reg_set_info,
+                                      const register_map_entry_t &reg) {
   const char *default_lldb_encoding = "uint";
   const char *lldb_encoding = default_lldb_encoding;
   const char *gdb_group = "general";
@@ -5135,7 +5101,7 @@ void GenerateTargetXMLRegister(std::ostringstream &s, const uint32_t reg_num,
   XMLElementStartEndAttributes(s, true);
 }
 
-void GenerateTargetXMLRegisters(std::ostringstream &s) {
+static void GenerateTargetXMLRegisters(std::ostringstream &s) {
   nub_size_t num_reg_sets = 0;
   const DNBRegisterSetInfo *reg_sets = DNBGetRegisterSetInfo(&num_reg_sets);
 
@@ -5174,7 +5140,7 @@ static const char *g_target_xml_footer = "</target>";
 
 static std::string g_target_xml;
 
-void UpdateTargetXML() {
+static void UpdateTargetXML() {
   std::ostringstream s;
   s << g_target_xml_header << std::endl;
 
@@ -5309,8 +5275,9 @@ rnb_err_t RNBRemote::HandlePacket_jGetDyldProcessState(const char *p) {
 // a one-level-deep JSON dictionary of key-value pairs.  e.g.
 // jThreadExtendedInfo:{"plo_pthread_tsd_base_address_offset":0,"plo_pthread_tsd_base_offset":224,"plo_pthread_tsd_entry_size":8,"thread":144305}]
 //
-uint64_t get_integer_value_for_key_name_from_json(const char *key,
-                                                  const char *json_string) {
+static uint64_t
+get_integer_value_for_key_name_from_json(const char *key,
+                                         const char *json_string) {
   uint64_t retval = INVALID_NUB_ADDRESS;
   std::string key_with_quotes = "\"";
   key_with_quotes += key;
@@ -5346,9 +5313,9 @@ uint64_t get_integer_value_for_key_name_from_json(const char *key,
 // Returns true if it was able to find the key name, and sets the 'value'
 // argument to the value found.
 
-bool get_boolean_value_for_key_name_from_json(const char *key,
-                                              const char *json_string,
-                                              bool &value) {
+static bool get_boolean_value_for_key_name_from_json(const char *key,
+                                                     const char *json_string,
+                                                     bool &value) {
   std::string key_with_quotes = "\"";
   key_with_quotes += key;
   key_with_quotes += "\"";
@@ -5385,7 +5352,7 @@ bool get_boolean_value_for_key_name_from_json(const char *key,
 // Returns true if it was able to find the key name, false if it did not.
 // "ints" will have all integers found in the array appended to it.
 
-bool get_array_of_ints_value_for_key_name_from_json(
+static bool get_array_of_ints_value_for_key_name_from_json(
     const char *key, const char *json_string, std::vector<uint64_t> &ints) {
   std::string key_with_quotes = "\"";
   key_with_quotes += key;

``````````

</details>


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


More information about the lldb-commits mailing list