Skip to content

Commit f9733fa

Browse files
committed
Friendlier, no need to use std::format directly in log_* anymore
1 parent 79fa7c6 commit f9733fa

28 files changed

+459
-487
lines changed

src/native/monodroid/debug.cc

+30-31
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,9 @@ Debug::monodroid_profiler_load (const char *libmono_path, const char *desc, cons
9595

9696
if (!found)
9797
log_warn (LOG_DEFAULT,
98-
std::format ("The '{}' profiler wasn't found in the main executable nor could it be loaded from '{}'.",
99-
mname.get (),
100-
libname.get ()
101-
)
98+
"The '{}' profiler wasn't found in the main executable nor could it be loaded from '{}'.",
99+
mname.get (),
100+
libname.get ()
102101
);
103102
}
104103

@@ -110,7 +109,7 @@ bool
110109
Debug::load_profiler (void *handle, const char *desc, const char *symbol)
111110
{
112111
ProfilerInitializer func = reinterpret_cast<ProfilerInitializer> (java_interop_lib_symbol (handle, symbol, nullptr));
113-
log_warn (LOG_DEFAULT, std::format ("Looking for profiler init symbol '{}'? {:p}", symbol, reinterpret_cast<void*>(func)));
112+
log_warn (LOG_DEFAULT, "Looking for profiler init symbol '{}'? {:p}", symbol, reinterpret_cast<void*>(func));
114113

115114
if (func != nullptr) {
116115
func (desc);
@@ -140,7 +139,7 @@ Debug::parse_options (char *options, ConnOptions *opts)
140139
{
141140
char **args, **ptr;
142141

143-
log_info (LOG_DEFAULT, std::format ("Connection options: '{}'", options));
142+
log_info (LOG_DEFAULT, "Connection options: '{}'", options);
144143

145144
args = Util::monodroid_strsplit (options, ",", 0);
146145

@@ -150,12 +149,12 @@ Debug::parse_options (char *options, ConnOptions *opts)
150149
if (strstr (arg, "port=") == arg) {
151150
int port = atoi (arg + strlen ("port="));
152151
if (port < 0 || port > std::numeric_limits<unsigned short>::max ()) {
153-
log_error (LOG_DEFAULT, std::format ("Invalid debug port value {}", port));
152+
log_error (LOG_DEFAULT, "Invalid debug port value {}", port);
154153
continue;
155154
}
156155

157156
conn_port = static_cast<uint16_t>(port);
158-
log_info (LOG_DEFAULT, std::format ("XS port = {}", conn_port));
157+
log_info (LOG_DEFAULT, "XS port = {}", conn_port);
159158
} else if (strstr (arg, "timeout=") == arg) {
160159
char *endp;
161160

@@ -164,7 +163,7 @@ Debug::parse_options (char *options, ConnOptions *opts)
164163
if ((endp == arg) || (*endp != '\0'))
165164
log_error (LOG_DEFAULT, "Invalid --timeout argument."sv);
166165
} else {
167-
log_info (LOG_DEFAULT, std::format ("Unknown connection option: '{}'", arg));
166+
log_info (LOG_DEFAULT, "Unknown connection option: '{}'", arg);
168167
}
169168
}
170169
}
@@ -188,7 +187,7 @@ Debug::start_connection (char *options)
188187
cur_time = time (nullptr);
189188

190189
if (opts.timeout_time && cur_time > opts.timeout_time) {
191-
log_warn (LOG_DEBUGGER, std::format ("Not connecting to IDE as the timeout value has been reached; current-time: {} timeout: {}", cur_time, opts.timeout_time));
190+
log_warn (LOG_DEBUGGER, "Not connecting to IDE as the timeout value has been reached; current-time: {} timeout: {}", cur_time, opts.timeout_time);
192191
return DebuggerConnectionStatus::Unconnected;
193192
}
194193

@@ -199,7 +198,7 @@ Debug::start_connection (char *options)
199198

200199
res = pthread_create (&conn_thread_id, nullptr, xamarin::android::conn_thread, this);
201200
if (res) {
202-
log_error (LOG_DEFAULT, std::format ("Failed to create connection thread: {}", strerror (errno)));
201+
log_error (LOG_DEFAULT, "Failed to create connection thread: {}", strerror (errno));
203202
return DebuggerConnectionStatus::Error;
204203
}
205204

@@ -263,20 +262,20 @@ Debug::process_connection (int fd)
263262
return false;
264263
}
265264
if (rv <= 0) {
266-
log_info (LOG_DEFAULT, std::format ("Error while receiving command from XS ({})", strerror (errno)));
265+
log_info (LOG_DEFAULT, "Error while receiving command from XS ({})", strerror (errno));
267266
return false;
268267
}
269268

270269
rv = Util::recv_uninterrupted (fd, command, cmd_len);
271270
if (rv <= 0) {
272-
log_info (LOG_DEFAULT, std::format ("Error while receiving command from XS ({})", strerror (errno)));
271+
log_info (LOG_DEFAULT, "Error while receiving command from XS ({})", strerror (errno));
273272
return false;
274273
}
275274

276275
// null-terminate
277276
command [cmd_len] = 0;
278277

279-
log_info (LOG_DEFAULT, std::format ("Received cmd: '{}'.", command));
278+
log_info (LOG_DEFAULT, "Received cmd: '{}'.", command);
280279

281280
if (process_cmd (fd, command))
282281
return true;
@@ -288,14 +287,14 @@ Debug::handle_server_connection (void)
288287
{
289288
int listen_socket = socket (PF_INET, SOCK_STREAM, IPPROTO_TCP);
290289
if (listen_socket == -1) {
291-
log_info (LOG_DEFAULT, std::format ("Could not create socket for XS to connect to: {}", strerror (errno)));
290+
log_info (LOG_DEFAULT, "Could not create socket for XS to connect to: {}", strerror (errno));
292291
return 1;
293292
}
294293

295294
int flags = 1;
296295
int rv = setsockopt (listen_socket, SOL_SOCKET, SO_REUSEADDR, &flags, sizeof (flags));
297296
if (rv == -1 && Util::should_log (LOG_DEFAULT)) {
298-
log_info_nocheck (LOG_DEFAULT, std::format ("Could not set SO_REUSEADDR on the listening socket ({})", strerror (errno)));
297+
log_info_nocheck_fmt (LOG_DEFAULT, "Could not set SO_REUSEADDR on the listening socket ({})", strerror (errno));
299298
// not a fatal failure
300299
}
301300

@@ -309,7 +308,7 @@ Debug::handle_server_connection (void)
309308
listen_addr.sin_addr.s_addr = INADDR_ANY;
310309
rv = bind (listen_socket, (struct sockaddr *) &listen_addr, sizeof (listen_addr));
311310
if (rv == -1) {
312-
log_info (LOG_DEFAULT, std::format ("Could not bind to address: {}", strerror (errno)));
311+
log_info (LOG_DEFAULT, "Could not bind to address: {}", strerror (errno));
313312
rv = 2;
314313
goto cleanup;
315314
}
@@ -321,7 +320,7 @@ Debug::handle_server_connection (void)
321320

322321
rv = listen (listen_socket, 1);
323322
if (rv == -1) {
324-
log_info (LOG_DEFAULT, std::format ("Could not listen for XS: {}", strerror (errno)));
323+
log_info (LOG_DEFAULT, "Could not listen for XS: {}", strerror (errno));
325324
rv = 2;
326325
goto cleanup;
327326
}
@@ -371,26 +370,26 @@ Debug::handle_server_connection (void)
371370
} while (rv == -1 && errno == EINTR);
372371

373372
if (rv == -1) {
374-
log_info (LOG_DEFAULT, std::format ("Failed while waiting for XS to connect: {}", strerror (errno)));
373+
log_info (LOG_DEFAULT, "Failed while waiting for XS to connect: {}", strerror (errno));
375374
rv = 2;
376375
goto cleanup;
377376
}
378377

379378
socklen_t len = sizeof (struct sockaddr_in);
380379
int fd = accept (listen_socket, (struct sockaddr *) &listen_addr, &len);
381380
if (fd == -1) {
382-
log_info (LOG_DEFAULT, std::format ("Failed to accept connection from XS: {}", strerror (errno)));
381+
log_info (LOG_DEFAULT, "Failed to accept connection from XS: {}", strerror (errno));
383382
rv = 3;
384383
goto cleanup;
385384
}
386385

387386
flags = 1;
388387
if (setsockopt (fd, IPPROTO_TCP, TCP_NODELAY, (char *) &flags, sizeof (flags)) < 0) {
389-
log_info (LOG_DEFAULT, std::format ("Could not set TCP_NODELAY on socket ({})", strerror (errno)));
388+
log_info (LOG_DEFAULT, "Could not set TCP_NODELAY on socket ({})", strerror (errno));
390389
// not a fatal failure
391390
}
392391

393-
log_info (LOG_DEFAULT, std::format ("Successfully received connection from XS on port {}, fd: {}", listen_port, fd));
392+
log_info (LOG_DEFAULT, "Successfully received connection from XS on port {}, fd: {}", listen_port, fd);
394393

395394
need_new_conn = process_connection (fd);
396395
}
@@ -442,7 +441,7 @@ Debug::process_cmd (int fd, char *cmd)
442441
constexpr std::string_view PONG_REPLY { "pong" };
443442
if (strcmp (cmd, PING_CMD.data ()) == 0) {
444443
if (!Util::send_uninterrupted (fd, const_cast<void*> (reinterpret_cast<const void*> (PONG_REPLY.data ())), 5))
445-
log_error (LOG_DEFAULT, std::format ("Got keepalive request from XS, but could not send response back ({})", strerror (errno)));
444+
log_error (LOG_DEFAULT, "Got keepalive request from XS, but could not send response back ({})", strerror (errno));
446445
return false;
447446
}
448447

@@ -488,7 +487,7 @@ Debug::process_cmd (int fd, char *cmd)
488487
profiler_fd = fd;
489488
profiler_description = Util::monodroid_strdup_printf ("%s,output=#%i", prof, profiler_fd);
490489
} else {
491-
log_error (LOG_DEFAULT, std::format ("Unknown profiler: '{}'", prof));
490+
log_error (LOG_DEFAULT, "Unknown profiler: '{}'", prof);
492491
}
493492
/* Notify the main thread (start_profiling ()) */
494493
profiler_configured = true;
@@ -497,7 +496,7 @@ Debug::process_cmd (int fd, char *cmd)
497496
pthread_mutex_unlock (&process_cmd_mutex);
498497
return use_fd;
499498
} else {
500-
log_error (LOG_DEFAULT, std::format ("Unsupported command: '{}'", cmd));
499+
log_error (LOG_DEFAULT, "Unsupported command: '{}'", cmd);
501500
}
502501

503502
return false;
@@ -527,7 +526,7 @@ Debug::start_debugging (void)
527526

528527
// this text is used in unit tests to check the debugger started
529528
// do not change it without updating the test.
530-
log_warn (LOG_DEBUGGER, std::format ("Trying to initialize the debugger with options: {}", debug_arg));
529+
log_warn (LOG_DEBUGGER, "Trying to initialize the debugger with options: {}", debug_arg);
531530

532531
if (enable_soft_breakpoints ()) {
533532
constexpr std::string_view soft_breakpoints { "--soft-breakpoints" };
@@ -554,7 +553,7 @@ Debug::start_profiling ()
554553
if (!profiler_description)
555554
return;
556555

557-
log_info (LOG_DEFAULT, std::format ("Loading profiler: '{}'", profiler_description));
556+
log_info (LOG_DEFAULT, "Loading profiler: '{}'", profiler_description);
558557
monodroid_profiler_load (AndroidSystem::get_runtime_libdir (), profiler_description, nullptr);
559558
}
560559

@@ -574,25 +573,25 @@ Debug::enable_soft_breakpoints (void)
574573
uname (&name);
575574
for (const char** ptr = soft_breakpoint_kernel_list; *ptr; ptr++) {
576575
if (strcmp (name.release, *ptr) == 0) {
577-
log_info (LOG_DEBUGGER, std::format ("soft breakpoints enabled due to kernel version match ({})", name.release));
576+
log_info (LOG_DEBUGGER, "soft breakpoints enabled due to kernel version match ({})", name.release);
578577
return 1;
579578
}
580579
}
581580

582581
char *value;
583582
/* Soft breakpoints are enabled by default */
584583
if (AndroidSystem::monodroid_get_system_property (SharedConstants::DEBUG_MONO_SOFT_BREAKPOINTS, &value) <= 0) {
585-
log_info (LOG_DEBUGGER, std::format ("soft breakpoints enabled by default ({} property not defined)", SharedConstants::DEBUG_MONO_SOFT_BREAKPOINTS.data ()));
584+
log_info (LOG_DEBUGGER, "soft breakpoints enabled by default ({} property not defined)", SharedConstants::DEBUG_MONO_SOFT_BREAKPOINTS.data ());
586585
return 1;
587586
}
588587

589588
bool ret;
590589
if (strcmp ("0", value) == 0) {
591590
ret = false;
592-
log_info (LOG_DEBUGGER, std::format ("soft breakpoints disabled ({} property set to {})", SharedConstants::DEBUG_MONO_SOFT_BREAKPOINTS.data (), value));
591+
log_info (LOG_DEBUGGER, "soft breakpoints disabled ({} property set to {})", SharedConstants::DEBUG_MONO_SOFT_BREAKPOINTS.data (), value);
593592
} else {
594593
ret = true;
595-
log_info (LOG_DEBUGGER, std::format ("soft breakpoints enabled ({} property set to {})", SharedConstants::DEBUG_MONO_SOFT_BREAKPOINTS.data (), value));
594+
log_info (LOG_DEBUGGER, "soft breakpoints enabled ({} property set to {})", SharedConstants::DEBUG_MONO_SOFT_BREAKPOINTS.data (), value);
596595
}
597596
delete[] value;
598597
return ret;

0 commit comments

Comments
 (0)