Skip to content

Commit 556e300

Browse files
[debugserver][NFC] Make helper functions have internal linkage (llvm#162307)
This also allowed deleting unreachable code. (cherry picked from commit 25933f6)
1 parent dc36087 commit 556e300

File tree

1 file changed

+40
-73
lines changed

1 file changed

+40
-73
lines changed

lldb/tools/debugserver/source/RNBRemote.cpp

Lines changed: 40 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ static const std::string JSON_ASYNC_TYPE_KEY_NAME("type");
8989
std::setfill(' ') << std::setw((iword_idx)) << ""
9090
#define INDENT_WITH_TABS(iword_idx) \
9191
std::setfill('\t') << std::setw((iword_idx)) << ""
92-
// Class to handle communications via gdb remote protocol.
9392

9493
// If `ch` is a meta character as per the binary packet convention in the
9594
// gdb-remote protocol, quote it and write it into `stream`, otherwise write it
@@ -159,16 +158,16 @@ static std::string decode_hex_ascii_string(const char *p,
159158
return arg;
160159
}
161160

162-
uint64_t decode_uint64(const char *p, int base, char **end = nullptr,
163-
uint64_t fail_value = 0) {
161+
static uint64_t decode_uint64(const char *p, int base, char **end = nullptr,
162+
uint64_t fail_value = 0) {
164163
nub_addr_t addr = strtoull(p, end, 16);
165164
if (addr == 0 && errno != 0)
166165
return fail_value;
167166
return addr;
168167
}
169168

170-
void append_hex_value(std::ostream &ostrm, const void *buf, size_t buf_size,
171-
bool swap) {
169+
static void append_hex_value(std::ostream &ostrm, const void *buf,
170+
size_t buf_size, bool swap) {
172171
int i;
173172
const uint8_t *p = (const uint8_t *)buf;
174173
if (swap) {
@@ -180,7 +179,7 @@ void append_hex_value(std::ostream &ostrm, const void *buf, size_t buf_size,
180179
}
181180
}
182181

183-
std::string cstring_to_asciihex_string(const char *str) {
182+
static std::string cstring_to_asciihex_string(const char *str) {
184183
std::string hex_str;
185184
hex_str.reserve(strlen(str) * 2);
186185
while (str && *str) {
@@ -192,7 +191,8 @@ std::string cstring_to_asciihex_string(const char *str) {
192191
return hex_str;
193192
}
194193

195-
void append_hexified_string(std::ostream &ostrm, const std::string &string) {
194+
static void append_hexified_string(std::ostream &ostrm,
195+
const std::string &string) {
196196
size_t string_size = string.size();
197197
const char *string_buf = string.c_str();
198198
for (size_t i = 0; i < string_size; i++) {
@@ -1045,8 +1045,6 @@ rnb_err_t RNBRemote::HandleAsyncPacket(PacketEnum *type) {
10451045
rnb_err_t RNBRemote::HandleReceivedPacket(PacketEnum *type) {
10461046
static DNBTimer g_packetTimer(true);
10471047

1048-
// DNBLogThreadedIf (LOG_RNB_REMOTE, "%8u RNBRemote::%s",
1049-
// (uint32_t)m_comm.Timer().ElapsedMicroSeconds(true), __FUNCTION__);
10501048
rnb_err_t err = rnb_err;
10511049
std::string packet_data;
10521050
RNBRemote::Packet packet_info;
@@ -1302,8 +1300,7 @@ static cpu_type_t best_guess_cpu_type() {
13021300
LEN is the number of bytes to be processed. If a character is escaped,
13031301
it is 2 characters for LEN. A LEN of -1 means decode-until-nul-byte
13041302
(end of string). */
1305-
1306-
std::vector<uint8_t> decode_binary_data(const char *str, size_t len) {
1303+
static std::vector<uint8_t> decode_binary_data(const char *str, size_t len) {
13071304
std::vector<uint8_t> bytes;
13081305
if (len == 0) {
13091306
return bytes;
@@ -1325,8 +1322,7 @@ std::vector<uint8_t> decode_binary_data(const char *str, size_t len) {
13251322
// If the value side of a key-value pair in JSON is a string,
13261323
// and that string has a " character in it, the " character must
13271324
// be escaped.
1328-
1329-
std::string json_string_quote_metachars(const std::string &s) {
1325+
static std::string json_string_quote_metachars(const std::string &s) {
13301326
if (s.find('"') == std::string::npos)
13311327
return s;
13321328

@@ -1460,15 +1456,6 @@ bool RNBRemote::InitializeRegisters(bool force) {
14601456
}
14611457
}
14621458

1463-
// for (auto &reg_entry: g_dynamic_register_map)
1464-
// {
1465-
// DNBLogThreaded("%4i: size = %3u, pseudo = %i, name = %s",
1466-
// reg_entry.offset,
1467-
// reg_entry.nub_info.size,
1468-
// reg_entry.nub_info.value_regs != NULL,
1469-
// reg_entry.nub_info.name);
1470-
// }
1471-
14721459
g_reg_entries = g_dynamic_register_map.data();
14731460
g_num_reg_entries = g_dynamic_register_map.size();
14741461
}
@@ -1717,7 +1704,7 @@ rnb_err_t RNBRemote::HandlePacket_qThreadExtraInfo(const char *p) {
17171704
return SendPacket("");
17181705
}
17191706

1720-
const char *k_space_delimiters = " \t";
1707+
static const char *k_space_delimiters = " \t";
17211708
static void skip_spaces(std::string &line) {
17221709
if (!line.empty()) {
17231710
size_t space_pos = line.find_first_not_of(k_space_delimiters);
@@ -2022,7 +2009,7 @@ rnb_err_t RNBRemote::HandlePacket_qRegisterInfo(const char *p) {
20222009
QSetLogging:bitmask=LOG_ALL;mode=asl;
20232010
*/
20242011

2025-
rnb_err_t set_logging(const char *p) {
2012+
static rnb_err_t set_logging(const char *p) {
20262013
int bitmask = 0;
20272014
while (p && *p != '\0') {
20282015
if (strncmp(p, "bitmask=", sizeof("bitmask=") - 1) == 0) {
@@ -2566,11 +2553,10 @@ rnb_err_t RNBRemote::HandlePacket_QSetProcessEvent(const char *p) {
25662553

25672554
// If a fail_value is provided, a correct-length reply is always provided,
25682555
// even if the register cannot be read right now on this thread.
2569-
bool register_value_in_hex_fixed_width(std::ostream &ostrm, nub_process_t pid,
2570-
nub_thread_t tid,
2571-
const register_map_entry_t *reg,
2572-
const DNBRegisterValue *reg_value_ptr,
2573-
std::optional<uint8_t> fail_value) {
2556+
static bool register_value_in_hex_fixed_width(
2557+
std::ostream &ostrm, nub_process_t pid, nub_thread_t tid,
2558+
const register_map_entry_t *reg, const DNBRegisterValue *reg_value_ptr,
2559+
std::optional<uint8_t> fail_value) {
25742560
if (reg != NULL) {
25752561
std::unique_ptr<DNBRegisterValue> reg_value =
25762562
std::make_unique<DNBRegisterValue>();
@@ -2597,7 +2583,7 @@ bool register_value_in_hex_fixed_width(std::ostream &ostrm, nub_process_t pid,
25972583
return false;
25982584
}
25992585

2600-
void debugserver_regnum_with_fixed_width_hex_register_value(
2586+
static void debugserver_regnum_with_fixed_width_hex_register_value(
26012587
std::ostream &ostrm, nub_process_t pid, nub_thread_t tid,
26022588
const register_map_entry_t *reg, const DNBRegisterValue *reg_value_ptr,
26032589
std::optional<uint8_t> fail_value) {
@@ -4808,52 +4794,31 @@ rnb_err_t RNBRemote::HandlePacket_qHostInfo(const char *p) {
48084794
return SendPacket(strm.str());
48094795
}
48104796

4811-
void XMLElementStart(std::ostringstream &s, uint32_t indent, const char *name,
4812-
bool has_attributes) {
4797+
static void XMLElementStart(std::ostringstream &s, uint32_t indent,
4798+
const char *name, bool has_attributes) {
48134799
if (indent)
48144800
s << INDENT_WITH_SPACES(indent);
48154801
s << '<' << name;
48164802
if (!has_attributes)
48174803
s << '>' << std::endl;
48184804
}
48194805

4820-
void XMLElementStartEndAttributes(std::ostringstream &s, bool empty) {
4806+
static void XMLElementStartEndAttributes(std::ostringstream &s, bool empty) {
48214807
if (empty)
48224808
s << '/';
48234809
s << '>' << std::endl;
48244810
}
48254811

4826-
void XMLElementEnd(std::ostringstream &s, uint32_t indent, const char *name) {
4812+
static void XMLElementEnd(std::ostringstream &s, uint32_t indent,
4813+
const char *name) {
48274814
if (indent)
48284815
s << INDENT_WITH_SPACES(indent);
48294816
s << '<' << '/' << name << '>' << std::endl;
48304817
}
48314818

4832-
void XMLElementWithStringValue(std::ostringstream &s, uint32_t indent,
4833-
const char *name, const char *value,
4834-
bool close = true) {
4835-
if (value) {
4836-
if (indent)
4837-
s << INDENT_WITH_SPACES(indent);
4838-
s << '<' << name << '>' << value;
4839-
if (close)
4840-
XMLElementEnd(s, 0, name);
4841-
}
4842-
}
4843-
4844-
void XMLElementWithUnsignedValue(std::ostringstream &s, uint32_t indent,
4845-
const char *name, uint64_t value,
4846-
bool close = true) {
4847-
if (indent)
4848-
s << INDENT_WITH_SPACES(indent);
4849-
4850-
s << '<' << name << '>' << DECIMAL << value;
4851-
if (close)
4852-
XMLElementEnd(s, 0, name);
4853-
}
4854-
4855-
void XMLAttributeString(std::ostringstream &s, const char *name,
4856-
const char *value, const char *default_value = NULL) {
4819+
static void XMLAttributeString(std::ostringstream &s, const char *name,
4820+
const char *value,
4821+
const char *default_value = NULL) {
48574822
if (value) {
48584823
if (default_value && strcmp(value, default_value) == 0)
48594824
return; // No need to emit the attribute because it matches the default
@@ -4862,15 +4827,16 @@ void XMLAttributeString(std::ostringstream &s, const char *name,
48624827
}
48634828
}
48644829

4865-
void XMLAttributeUnsignedDecimal(std::ostringstream &s, const char *name,
4866-
uint64_t value) {
4830+
static void XMLAttributeUnsignedDecimal(std::ostringstream &s, const char *name,
4831+
uint64_t value) {
48674832
s << ' ' << name << "=\"" << DECIMAL << value << "\"";
48684833
}
48694834

4870-
void GenerateTargetXMLRegister(std::ostringstream &s, const uint32_t reg_num,
4871-
nub_size_t num_reg_sets,
4872-
const DNBRegisterSetInfo *reg_set_info,
4873-
const register_map_entry_t &reg) {
4835+
static void GenerateTargetXMLRegister(std::ostringstream &s,
4836+
const uint32_t reg_num,
4837+
nub_size_t num_reg_sets,
4838+
const DNBRegisterSetInfo *reg_set_info,
4839+
const register_map_entry_t &reg) {
48744840
const char *default_lldb_encoding = "uint";
48754841
const char *lldb_encoding = default_lldb_encoding;
48764842
const char *gdb_group = "general";
@@ -5041,7 +5007,7 @@ void GenerateTargetXMLRegister(std::ostringstream &s, const uint32_t reg_num,
50415007
XMLElementStartEndAttributes(s, true);
50425008
}
50435009

5044-
void GenerateTargetXMLRegisters(std::ostringstream &s) {
5010+
static void GenerateTargetXMLRegisters(std::ostringstream &s) {
50455011
nub_size_t num_reg_sets = 0;
50465012
const DNBRegisterSetInfo *reg_sets = DNBGetRegisterSetInfo(&num_reg_sets);
50475013

@@ -5080,7 +5046,7 @@ static const char *g_target_xml_footer = "</target>";
50805046

50815047
static std::string g_target_xml;
50825048

5083-
void UpdateTargetXML() {
5049+
static void UpdateTargetXML() {
50845050
std::ostringstream s;
50855051
s << g_target_xml_header << std::endl;
50865052

@@ -5215,8 +5181,9 @@ rnb_err_t RNBRemote::HandlePacket_jGetDyldProcessState(const char *p) {
52155181
// a one-level-deep JSON dictionary of key-value pairs. e.g.
52165182
// jThreadExtendedInfo:{"plo_pthread_tsd_base_address_offset":0,"plo_pthread_tsd_base_offset":224,"plo_pthread_tsd_entry_size":8,"thread":144305}]
52175183
//
5218-
uint64_t get_integer_value_for_key_name_from_json(const char *key,
5219-
const char *json_string) {
5184+
static uint64_t
5185+
get_integer_value_for_key_name_from_json(const char *key,
5186+
const char *json_string) {
52205187
uint64_t retval = INVALID_NUB_ADDRESS;
52215188
std::string key_with_quotes = "\"";
52225189
key_with_quotes += key;
@@ -5252,9 +5219,9 @@ uint64_t get_integer_value_for_key_name_from_json(const char *key,
52525219
// Returns true if it was able to find the key name, and sets the 'value'
52535220
// argument to the value found.
52545221

5255-
bool get_boolean_value_for_key_name_from_json(const char *key,
5256-
const char *json_string,
5257-
bool &value) {
5222+
static bool get_boolean_value_for_key_name_from_json(const char *key,
5223+
const char *json_string,
5224+
bool &value) {
52585225
std::string key_with_quotes = "\"";
52595226
key_with_quotes += key;
52605227
key_with_quotes += "\"";
@@ -5291,7 +5258,7 @@ bool get_boolean_value_for_key_name_from_json(const char *key,
52915258
// Returns true if it was able to find the key name, false if it did not.
52925259
// "ints" will have all integers found in the array appended to it.
52935260

5294-
bool get_array_of_ints_value_for_key_name_from_json(
5261+
static bool get_array_of_ints_value_for_key_name_from_json(
52955262
const char *key, const char *json_string, std::vector<uint64_t> &ints) {
52965263
std::string key_with_quotes = "\"";
52975264
key_with_quotes += key;

0 commit comments

Comments
 (0)