Skip to content

Commit 61a73a7

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 0f9b86a commit 61a73a7

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
@@ -90,7 +90,6 @@ static const std::string JSON_ASYNC_TYPE_KEY_NAME("type");
9090
std::setfill(' ') << std::setw((iword_idx)) << ""
9191
#define INDENT_WITH_TABS(iword_idx) \
9292
std::setfill('\t') << std::setw((iword_idx)) << ""
93-
// Class to handle communications via gdb remote protocol.
9493

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

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

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

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

196-
void append_hexified_string(std::ostream &ostrm, const std::string &string) {
195+
static void append_hexified_string(std::ostream &ostrm,
196+
const std::string &string) {
197197
size_t string_size = string.size();
198198
const char *string_buf = string.c_str();
199199
for (size_t i = 0; i < string_size; i++) {
@@ -1050,8 +1050,6 @@ rnb_err_t RNBRemote::HandleAsyncPacket(PacketEnum *type) {
10501050
rnb_err_t RNBRemote::HandleReceivedPacket(PacketEnum *type) {
10511051
static DNBTimer g_packetTimer(true);
10521052

1053-
// DNBLogThreadedIf (LOG_RNB_REMOTE, "%8u RNBRemote::%s",
1054-
// (uint32_t)m_comm.Timer().ElapsedMicroSeconds(true), __FUNCTION__);
10551053
rnb_err_t err = rnb_err;
10561054
std::string packet_data;
10571055
RNBRemote::Packet packet_info;
@@ -1307,8 +1305,7 @@ static cpu_type_t best_guess_cpu_type() {
13071305
LEN is the number of bytes to be processed. If a character is escaped,
13081306
it is 2 characters for LEN. A LEN of -1 means decode-until-nul-byte
13091307
(end of string). */
1310-
1311-
std::vector<uint8_t> decode_binary_data(const char *str, size_t len) {
1308+
static std::vector<uint8_t> decode_binary_data(const char *str, size_t len) {
13121309
std::vector<uint8_t> bytes;
13131310
if (len == 0) {
13141311
return bytes;
@@ -1330,8 +1327,7 @@ std::vector<uint8_t> decode_binary_data(const char *str, size_t len) {
13301327
// If the value side of a key-value pair in JSON is a string,
13311328
// and that string has a " character in it, the " character must
13321329
// be escaped.
1333-
1334-
std::string json_string_quote_metachars(const std::string &s) {
1330+
static std::string json_string_quote_metachars(const std::string &s) {
13351331
if (s.find('"') == std::string::npos)
13361332
return s;
13371333

@@ -1465,15 +1461,6 @@ bool RNBRemote::InitializeRegisters(bool force) {
14651461
}
14661462
}
14671463

1468-
// for (auto &reg_entry: g_dynamic_register_map)
1469-
// {
1470-
// DNBLogThreaded("%4i: size = %3u, pseudo = %i, name = %s",
1471-
// reg_entry.offset,
1472-
// reg_entry.nub_info.size,
1473-
// reg_entry.nub_info.value_regs != NULL,
1474-
// reg_entry.nub_info.name);
1475-
// }
1476-
14771464
g_reg_entries = g_dynamic_register_map.data();
14781465
g_num_reg_entries = g_dynamic_register_map.size();
14791466
}
@@ -1723,7 +1710,7 @@ rnb_err_t RNBRemote::HandlePacket_qThreadExtraInfo(const char *p) {
17231710
return SendPacket("");
17241711
}
17251712

1726-
const char *k_space_delimiters = " \t";
1713+
static const char *k_space_delimiters = " \t";
17271714
static void skip_spaces(std::string &line) {
17281715
if (!line.empty()) {
17291716
size_t space_pos = line.find_first_not_of(k_space_delimiters);
@@ -2028,7 +2015,7 @@ rnb_err_t RNBRemote::HandlePacket_qRegisterInfo(const char *p) {
20282015
QSetLogging:bitmask=LOG_ALL;mode=asl;
20292016
*/
20302017

2031-
rnb_err_t set_logging(const char *p) {
2018+
static rnb_err_t set_logging(const char *p) {
20322019
int bitmask = 0;
20332020
while (p && *p != '\0') {
20342021
if (strncmp(p, "bitmask=", sizeof("bitmask=") - 1) == 0) {
@@ -2572,11 +2559,10 @@ rnb_err_t RNBRemote::HandlePacket_QSetProcessEvent(const char *p) {
25722559

25732560
// If a fail_value is provided, a correct-length reply is always provided,
25742561
// even if the register cannot be read right now on this thread.
2575-
bool register_value_in_hex_fixed_width(std::ostream &ostrm, nub_process_t pid,
2576-
nub_thread_t tid,
2577-
const register_map_entry_t *reg,
2578-
const DNBRegisterValue *reg_value_ptr,
2579-
std::optional<uint8_t> fail_value) {
2562+
static bool register_value_in_hex_fixed_width(
2563+
std::ostream &ostrm, nub_process_t pid, nub_thread_t tid,
2564+
const register_map_entry_t *reg, const DNBRegisterValue *reg_value_ptr,
2565+
std::optional<uint8_t> fail_value) {
25802566
if (reg != NULL) {
25812567
std::unique_ptr<DNBRegisterValue> reg_value =
25822568
std::make_unique<DNBRegisterValue>();
@@ -2603,7 +2589,7 @@ bool register_value_in_hex_fixed_width(std::ostream &ostrm, nub_process_t pid,
26032589
return false;
26042590
}
26052591

2606-
void debugserver_regnum_with_fixed_width_hex_register_value(
2592+
static void debugserver_regnum_with_fixed_width_hex_register_value(
26072593
std::ostream &ostrm, nub_process_t pid, nub_thread_t tid,
26082594
const register_map_entry_t *reg, const DNBRegisterValue *reg_value_ptr,
26092595
std::optional<uint8_t> fail_value) {
@@ -4905,52 +4891,31 @@ rnb_err_t RNBRemote::HandlePacket_qHostInfo(const char *p) {
49054891
return SendPacket(strm.str());
49064892
}
49074893

4908-
void XMLElementStart(std::ostringstream &s, uint32_t indent, const char *name,
4909-
bool has_attributes) {
4894+
static void XMLElementStart(std::ostringstream &s, uint32_t indent,
4895+
const char *name, bool has_attributes) {
49104896
if (indent)
49114897
s << INDENT_WITH_SPACES(indent);
49124898
s << '<' << name;
49134899
if (!has_attributes)
49144900
s << '>' << std::endl;
49154901
}
49164902

4917-
void XMLElementStartEndAttributes(std::ostringstream &s, bool empty) {
4903+
static void XMLElementStartEndAttributes(std::ostringstream &s, bool empty) {
49184904
if (empty)
49194905
s << '/';
49204906
s << '>' << std::endl;
49214907
}
49224908

4923-
void XMLElementEnd(std::ostringstream &s, uint32_t indent, const char *name) {
4909+
static void XMLElementEnd(std::ostringstream &s, uint32_t indent,
4910+
const char *name) {
49244911
if (indent)
49254912
s << INDENT_WITH_SPACES(indent);
49264913
s << '<' << '/' << name << '>' << std::endl;
49274914
}
49284915

4929-
void XMLElementWithStringValue(std::ostringstream &s, uint32_t indent,
4930-
const char *name, const char *value,
4931-
bool close = true) {
4932-
if (value) {
4933-
if (indent)
4934-
s << INDENT_WITH_SPACES(indent);
4935-
s << '<' << name << '>' << value;
4936-
if (close)
4937-
XMLElementEnd(s, 0, name);
4938-
}
4939-
}
4940-
4941-
void XMLElementWithUnsignedValue(std::ostringstream &s, uint32_t indent,
4942-
const char *name, uint64_t value,
4943-
bool close = true) {
4944-
if (indent)
4945-
s << INDENT_WITH_SPACES(indent);
4946-
4947-
s << '<' << name << '>' << DECIMAL << value;
4948-
if (close)
4949-
XMLElementEnd(s, 0, name);
4950-
}
4951-
4952-
void XMLAttributeString(std::ostringstream &s, const char *name,
4953-
const char *value, const char *default_value = NULL) {
4916+
static void XMLAttributeString(std::ostringstream &s, const char *name,
4917+
const char *value,
4918+
const char *default_value = NULL) {
49544919
if (value) {
49554920
if (default_value && strcmp(value, default_value) == 0)
49564921
return; // No need to emit the attribute because it matches the default
@@ -4959,15 +4924,16 @@ void XMLAttributeString(std::ostringstream &s, const char *name,
49594924
}
49604925
}
49614926

4962-
void XMLAttributeUnsignedDecimal(std::ostringstream &s, const char *name,
4963-
uint64_t value) {
4927+
static void XMLAttributeUnsignedDecimal(std::ostringstream &s, const char *name,
4928+
uint64_t value) {
49644929
s << ' ' << name << "=\"" << DECIMAL << value << "\"";
49654930
}
49664931

4967-
void GenerateTargetXMLRegister(std::ostringstream &s, const uint32_t reg_num,
4968-
nub_size_t num_reg_sets,
4969-
const DNBRegisterSetInfo *reg_set_info,
4970-
const register_map_entry_t &reg) {
4932+
static void GenerateTargetXMLRegister(std::ostringstream &s,
4933+
const uint32_t reg_num,
4934+
nub_size_t num_reg_sets,
4935+
const DNBRegisterSetInfo *reg_set_info,
4936+
const register_map_entry_t &reg) {
49714937
const char *default_lldb_encoding = "uint";
49724938
const char *lldb_encoding = default_lldb_encoding;
49734939
const char *gdb_group = "general";
@@ -5138,7 +5104,7 @@ void GenerateTargetXMLRegister(std::ostringstream &s, const uint32_t reg_num,
51385104
XMLElementStartEndAttributes(s, true);
51395105
}
51405106

5141-
void GenerateTargetXMLRegisters(std::ostringstream &s) {
5107+
static void GenerateTargetXMLRegisters(std::ostringstream &s) {
51425108
nub_size_t num_reg_sets = 0;
51435109
const DNBRegisterSetInfo *reg_sets = DNBGetRegisterSetInfo(&num_reg_sets);
51445110

@@ -5177,7 +5143,7 @@ static const char *g_target_xml_footer = "</target>";
51775143

51785144
static std::string g_target_xml;
51795145

5180-
void UpdateTargetXML() {
5146+
static void UpdateTargetXML() {
51815147
std::ostringstream s;
51825148
s << g_target_xml_header << std::endl;
51835149

@@ -5312,8 +5278,9 @@ rnb_err_t RNBRemote::HandlePacket_jGetDyldProcessState(const char *p) {
53125278
// a one-level-deep JSON dictionary of key-value pairs. e.g.
53135279
// jThreadExtendedInfo:{"plo_pthread_tsd_base_address_offset":0,"plo_pthread_tsd_base_offset":224,"plo_pthread_tsd_entry_size":8,"thread":144305}]
53145280
//
5315-
uint64_t get_integer_value_for_key_name_from_json(const char *key,
5316-
const char *json_string) {
5281+
static uint64_t
5282+
get_integer_value_for_key_name_from_json(const char *key,
5283+
const char *json_string) {
53175284
uint64_t retval = INVALID_NUB_ADDRESS;
53185285
std::string key_with_quotes = "\"";
53195286
key_with_quotes += key;
@@ -5349,9 +5316,9 @@ uint64_t get_integer_value_for_key_name_from_json(const char *key,
53495316
// Returns true if it was able to find the key name, and sets the 'value'
53505317
// argument to the value found.
53515318

5352-
bool get_boolean_value_for_key_name_from_json(const char *key,
5353-
const char *json_string,
5354-
bool &value) {
5319+
static bool get_boolean_value_for_key_name_from_json(const char *key,
5320+
const char *json_string,
5321+
bool &value) {
53555322
std::string key_with_quotes = "\"";
53565323
key_with_quotes += key;
53575324
key_with_quotes += "\"";
@@ -5388,7 +5355,7 @@ bool get_boolean_value_for_key_name_from_json(const char *key,
53885355
// Returns true if it was able to find the key name, false if it did not.
53895356
// "ints" will have all integers found in the array appended to it.
53905357

5391-
bool get_array_of_ints_value_for_key_name_from_json(
5358+
static bool get_array_of_ints_value_for_key_name_from_json(
53925359
const char *key, const char *json_string, std::vector<uint64_t> &ints) {
53935360
std::string key_with_quotes = "\"";
53945361
key_with_quotes += key;

0 commit comments

Comments
 (0)