Skip to content

Commit 040ef4c

Browse files
committed
Remove ro.debuggable and enable critical logs for all builds
Removed ro.debuggable property and enabled critical logs across all build types. Signed-off-by: Vinayak Katoch <[email protected]>
1 parent 59c8b54 commit 040ef4c

File tree

3 files changed

+52
-54
lines changed

3 files changed

+52
-54
lines changed

inc/fastrpc_common.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,6 @@
126126
FASTRPC_ENABLE_SYSTRACE = 6, //to enable tracing using Systrace
127127
FASTRPC_DEBUG_PDDUMP = 7, // to enable pd dump debug data collection on rooted device for signed/unsigned pd
128128
FASTRPC_PROCESS_ATTRS_PERSISTENT = 8, // to set proc attr as persistent
129-
FASTRPC_BUILD_TYPE = 9 // Fetch build type of firmware image. It gives the details if its debug or prod build
130129
}fastrpc_properties;
131130

132131
/**

src/fastrpc_apps_user.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -225,8 +225,7 @@ const char *ENV_DEBUG_VAR_NAME[] = {"FASTRPC_PROCESS_ATTRS",
225225
"FASTRPC_PERF_FREQ",
226226
"FASTRPC_DEBUG_SYSTRACE",
227227
"FASTRPC_DEBUG_PDDUMP",
228-
"FASTRPC_PROCESS_ATTRS_PERSISTENT",
229-
"ro.debuggable"};
228+
"FASTRPC_PROCESS_ATTRS_PERSISTENT"};
230229

231230
const char *SUBSYSTEM_NAME[] = {"adsp", "mdsp", "sdsp", "cdsp", "cdsp1", "gdsp0", "gdsp1", "reserved"};
232231

@@ -3141,6 +3140,7 @@ static void domain_deinit(int domain) {
31413140
trace_marker_deinit(domain);
31423141
deinitFileWatcher(domain);
31433142
adspmsgd_stop(domain);
3143+
fastrpc_log_deinit();
31443144
fastrpc_mem_close(domain);
31453145
apps_mem_deinit(domain);
31463146
hlist[domain].state = 0;
@@ -3900,7 +3900,7 @@ static int domain_init(int domain, int *dev) {
39003900
}
39013901
VERIFY(AEE_SUCCESS == (nErr = fastrpc_mem_open(domain)));
39023902
VERIFY(AEE_SUCCESS == (nErr = apps_mem_init(domain)));
3903-
3903+
fastrpc_log_init();
39043904
if (dom == CDSP_DOMAIN_ID || dom == CDSP1_DOMAIN_ID || dom == GDSP0_DOMAIN_ID || dom == GDSP1_DOMAIN_ID) {
39053905
panic_handle = get_adsp_current_process1_handle(domain);
39063906
if (panic_handle != INVALID_HANDLE) {
@@ -4011,7 +4011,6 @@ static void fastrpc_apps_user_deinit(void) {
40114011
fastrpc_notif_deinit();
40124012
apps_mem_table_deinit();
40134013
fastrpc_wake_lock_deinit();
4014-
fastrpc_log_deinit();
40154014
fastrpc_mem_deinit();
40164015
PL_DEINIT(apps_std);
40174016
PL_DEINIT(rpcmem);
@@ -4073,7 +4072,6 @@ static int fastrpc_apps_user_init(void) {
40734072
VERIFY(AEE_SUCCESS == (nErr = PL_INIT(rpcmem)));
40744073
fastrpc_mem_init();
40754074
fastrpc_context_table_init();
4076-
fastrpc_log_init();
40774075
fastrpc_config_init();
40784076
pthread_mutex_init(&update_notif_list_mut, 0);
40794077
VERIFYC(NULL != (hlist = calloc(NUM_DOMAINS_EXTEND, sizeof(*hlist))),

src/fastrpc_log.c

Lines changed: 49 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -162,44 +162,59 @@ void HAP_debug_runtime(int level, const char *file, int line,
162162
const char *format, ...) {
163163
int len = 0;
164164
va_list argp;
165-
char *buf = NULL, *log = NULL;
166-
167-
/*
168-
* Adding logs to persist buffer when level is set to
169-
* RUNTIME_RPC_CRITICAL and fastrpc_log mask is disabled.
170-
*/
171-
if (((1 << level) & (fastrpc_logmask)) ||
172-
((level == HAP_LEVEL_RPC_CRITICAL) && persist_buf.buf) ||
173-
log_userspace_file_fd != NULL) {
174-
buf = (char *)malloc(sizeof(char) * MAX_FARF_LEN);
175-
if (buf == NULL) {
176-
return;
177-
}
178-
va_start(argp, format);
179-
len = vsnprintf(buf, MAX_FARF_LEN, format, argp);
180-
va_end(argp);
181-
log = (char *)malloc(sizeof(char) * MAX_FARF_LEN);
182-
if (log == NULL) {
183-
return;
184-
}
185-
snprintf(log, MAX_FARF_LEN, "%d:%d:%s:%s:%d: %s", getpid(), gettid(),
186-
__progname, file, line, buf);
165+
char *buf = NULL;
166+
const uint32_t level_mask = (1 << level);
167+
const bool log_enabled = (level_mask & fastrpc_logmask);
168+
const bool is_critical = (level == HAP_LEVEL_RPC_CRITICAL);
169+
const bool need_persist = is_critical && persist_buf.buf;
170+
const bool need_file_log = (log_userspace_file_fd != NULL);
171+
172+
/* Early return if no logging is needed */
173+
if (!log_enabled && !need_persist && !need_file_log) {
174+
return;
187175
}
188176

189-
print_dbgbuf_data(log, len);
190-
if (((1 << level) & (fastrpc_logmask))) {
191-
if (log_userspace_file_fd != NULL) {
192-
fputs(log, log_userspace_file_fd);
193-
fputs("\n", log_userspace_file_fd);
194-
}
195-
HAP_debug(buf, level, file, line);
177+
/* Allocate buffer only when needed */
178+
buf = (char *)malloc(sizeof(char) * MAX_FARF_LEN);
179+
if (buf == NULL) {
180+
return;
196181
}
197-
if (buf) {
182+
183+
/* Format the message once */
184+
va_start(argp, format);
185+
len = vsnprintf(buf, MAX_FARF_LEN, format, argp);
186+
va_end(argp);
187+
188+
/* Validate length */
189+
if (len <= 0 || len >= MAX_FARF_LEN) {
198190
free(buf);
191+
return;
199192
}
200-
if (log) {
201-
free(log);
193+
194+
/* Handle persist buffer for critical logs */
195+
if (need_persist || (log_enabled && IS_PERSIST_BUF_DATA(len, level))) {
196+
print_dbgbuf_data(buf, len);
202197
}
198+
199+
/* Handle regular logging when enabled */
200+
if (log_enabled) {
201+
/* File logging */
202+
if (need_file_log) {
203+
char *filelog = (char *)malloc(sizeof(char) * MAX_FARF_LEN);
204+
if (filelog) {
205+
if (snprintf(filelog, MAX_FARF_LEN, "%d:%d:%s:%s:%d: %s",
206+
getpid(), gettid(), __progname, file, line, buf) > 0) {
207+
fputs(filelog, log_userspace_file_fd);
208+
fputs("\n", log_userspace_file_fd);
209+
}
210+
free(filelog);
211+
}
212+
}
213+
/* Debug output */
214+
HAP_debug(buf, level, file, line);
215+
}
216+
217+
free(buf);
203218
}
204219

205220
#ifdef __LE_TVM__
@@ -279,28 +294,14 @@ void HAP_debug(const char *msg, int level, const char *filename, int line) {
279294
}
280295

281296
void fastrpc_log_init() {
282-
bool debug_build_type = false;
283297
int nErr = AEE_SUCCESS, fd = -1;
284298
char build_type[PROPERTY_VALUE_MAX];
285299
char *logfilename;
286300

287301
pthread_mutex_init(&persist_buf.mut, 0);
288302
pthread_mutex_lock(&persist_buf.mut);
289-
/*
290-
* Get build type by reading the target properties,
291-
* if buuid type is eng or userdebug allocate 1 MB persist buf.
292-
*/
293-
if (fastrpc_get_property_string(FASTRPC_BUILD_TYPE, build_type, NULL)) {
294-
#if !defined(LE_ENABLE)
295-
if (!strncmp(build_type, "eng", PROPERTY_VALUE_MAX) ||
296-
!strncmp(build_type, "userdebug", PROPERTY_VALUE_MAX))
297-
debug_build_type = true;
298-
#else
299-
if (atoi(build_type))
300-
debug_build_type = true;
301-
#endif
302-
}
303-
if (persist_buf.buf == NULL && debug_build_type) {
303+
304+
if (persist_buf.buf == NULL) {
304305
/* Create a debug buffer to append DEBUG FARF level message. */
305306
persist_buf.buf = (char *)rpcmem_alloc_internal(
306307
RPCMEM_HEAP_ID_SYSTEM, RPCMEM_DEFAULT_FLAGS | RPCMEM_TRY_MAP_STATIC,

0 commit comments

Comments
 (0)