mcexec: always compile debug statements
This helps catching errors like accessing a field that no longer exists in a debug print that wasn't compiled... Change-Id: If6c862ea2b866f819195aae93c7fd68e610fe48e
This commit is contained in:
committed by
Dominique Martinet
parent
9a79920ef9
commit
a1b50051ed
@@ -95,36 +95,39 @@
|
|||||||
//#define DEBUG
|
//#define DEBUG
|
||||||
#define ADD_ENVS_OPTION
|
#define ADD_ENVS_OPTION
|
||||||
|
|
||||||
#ifndef DEBUG
|
#ifdef DEBUG
|
||||||
#define __dprint(msg)
|
static int debug = 1;
|
||||||
#define __dprintf(arg, ...)
|
|
||||||
#define __eprint(msg)
|
|
||||||
#define __eprintf(format, ...)
|
|
||||||
#else
|
#else
|
||||||
#define __dprint(msg) {printf("%s: " msg, __FUNCTION__);fflush(stdout);}
|
static int debug;
|
||||||
#define __dprintf(format, args...) {printf("%s: " format, __FUNCTION__, \
|
|
||||||
##args);fflush(stdout);}
|
|
||||||
#define __eprint(msg) {fprintf(stderr, "%s: " msg, __FUNCTION__);fflush(stderr);}
|
|
||||||
#define __eprintf(format, args...) {fprintf(stderr, "%s: " format, __FUNCTION__, \
|
|
||||||
##args);fflush(stderr);}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define CHKANDJUMPF(cond, err, format, ...) \
|
#define __dprintf(format, args...) do { \
|
||||||
do { \
|
if (debug) { \
|
||||||
if(cond) { \
|
printf("%s: " format, __func__, ##args); \
|
||||||
__eprintf(format, __VA_ARGS__); \
|
fflush(stdout); \
|
||||||
ret = err; \
|
} \
|
||||||
goto fn_fail; \
|
} while (0)
|
||||||
} \
|
#define __eprintf(format, args...) do { \
|
||||||
|
fprintf(stderr, "%s: " format, __func__, ##args); \
|
||||||
|
fflush(stderr); \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
#define CHKANDJUMPF(cond, err, format, ...) \
|
||||||
|
do { \
|
||||||
|
if (cond) { \
|
||||||
|
__eprintf(format, __VA_ARGS__); \
|
||||||
|
ret = err; \
|
||||||
|
goto fn_fail; \
|
||||||
|
} \
|
||||||
} while(0)
|
} while(0)
|
||||||
|
|
||||||
#define CHKANDJUMP(cond, err, msg) \
|
#define CHKANDJUMP(cond, err, msg) \
|
||||||
do { \
|
do { \
|
||||||
if(cond) { \
|
if (cond) { \
|
||||||
__eprint(msg); \
|
__eprintf(msg); \
|
||||||
ret = err; \
|
ret = err; \
|
||||||
goto fn_fail; \
|
goto fn_fail; \
|
||||||
} \
|
} \
|
||||||
} while(0)
|
} while(0)
|
||||||
|
|
||||||
|
|
||||||
@@ -278,11 +281,11 @@ struct program_load_desc *load_elf(FILE *fp, char **interp_pathp)
|
|||||||
*interp_pathp = NULL;
|
*interp_pathp = NULL;
|
||||||
|
|
||||||
if (fread(&hdr, sizeof(hdr), 1, fp) < 1) {
|
if (fread(&hdr, sizeof(hdr), 1, fp) < 1) {
|
||||||
__eprint("Cannot read Ehdr.\n");
|
__eprintf("Cannot read Ehdr.\n");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (memcmp(hdr.e_ident, ELFMAG, SELFMAG)) {
|
if (memcmp(hdr.e_ident, ELFMAG, SELFMAG)) {
|
||||||
__eprint("ELFMAG mismatched.\n");
|
__eprintf("ELFMAG mismatched.\n");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
fseek(fp, hdr.e_phoff, SEEK_SET);
|
fseek(fp, hdr.e_phoff, SEEK_SET);
|
||||||
@@ -312,13 +315,13 @@ struct program_load_desc *load_elf(FILE *fp, char **interp_pathp)
|
|||||||
}
|
}
|
||||||
if (phdr.p_type == PT_INTERP) {
|
if (phdr.p_type == PT_INTERP) {
|
||||||
if (phdr.p_filesz > sizeof(interp_path)) {
|
if (phdr.p_filesz > sizeof(interp_path)) {
|
||||||
__eprint("too large PT_INTERP segment\n");
|
__eprintf("too large PT_INTERP segment\n");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
ss = pread(fileno(fp), interp_path, phdr.p_filesz,
|
ss = pread(fileno(fp), interp_path, phdr.p_filesz,
|
||||||
phdr.p_offset);
|
phdr.p_offset);
|
||||||
if (ss <= 0) {
|
if (ss <= 0) {
|
||||||
__eprint("cannot read PT_INTERP segment\n");
|
__eprintf("cannot read PT_INTERP segment\n");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
interp_path[ss] = '\0';
|
interp_path[ss] = '\0';
|
||||||
@@ -408,11 +411,11 @@ struct program_load_desc *load_interp(struct program_load_desc *desc0, FILE *fp)
|
|||||||
unsigned long align;
|
unsigned long align;
|
||||||
|
|
||||||
if (fread(&hdr, sizeof(hdr), 1, fp) < 1) {
|
if (fread(&hdr, sizeof(hdr), 1, fp) < 1) {
|
||||||
__eprint("Cannot read Ehdr.\n");
|
__eprintf("Cannot read Ehdr.\n");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (memcmp(hdr.e_ident, ELFMAG, SELFMAG)) {
|
if (memcmp(hdr.e_ident, ELFMAG, SELFMAG)) {
|
||||||
__eprint("ELFMAG mismatched.\n");
|
__eprintf("ELFMAG mismatched.\n");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
fseek(fp, hdr.e_phoff, SEEK_SET);
|
fseek(fp, hdr.e_phoff, SEEK_SET);
|
||||||
@@ -445,7 +448,7 @@ struct program_load_desc *load_interp(struct program_load_desc *desc0, FILE *fp)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (phdr.p_type == PT_INTERP) {
|
if (phdr.p_type == PT_INTERP) {
|
||||||
__eprint("PT_INTERP on interp\n");
|
__eprintf("PT_INTERP on interp\n");
|
||||||
free(desc);
|
free(desc);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@@ -603,7 +606,7 @@ retry:
|
|||||||
|
|
||||||
/* Check whether the resolved path is a symlink */
|
/* Check whether the resolved path is a symlink */
|
||||||
if (lstat(path, &sb) == -1) {
|
if (lstat(path, &sb) == -1) {
|
||||||
__eprint("lookup_exec_path(): error stat\n");
|
__eprintf("lookup_exec_path(): error stat\n");
|
||||||
return errno;
|
return errno;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -916,9 +919,8 @@ void print_desc(struct program_load_desc *desc)
|
|||||||
int i;
|
int i;
|
||||||
|
|
||||||
__dprintf("Desc (%p)\n", desc);
|
__dprintf("Desc (%p)\n", desc);
|
||||||
__dprintf("Status = %d, CPU = %d, pid = %d, entry = %lx, rp = %lx\n",
|
__dprintf("CPU = %d, pid = %d, entry = %lx, rp = %lx\n",
|
||||||
desc->status, desc->cpu, desc->pid, desc->entry,
|
desc->cpu, desc->pid, desc->entry, desc->rprocess);
|
||||||
desc->rprocess);
|
|
||||||
for (i = 0; i < desc->num_sections; i++) {
|
for (i = 0; i < desc->num_sections; i++) {
|
||||||
__dprintf("vaddr: %lx, mem_len: %lx, remote_pa: %lx, files: %lx\n",
|
__dprintf("vaddr: %lx, mem_len: %lx, remote_pa: %lx, files: %lx\n",
|
||||||
desc->sections[i].vaddr, desc->sections[i].len,
|
desc->sections[i].vaddr, desc->sections[i].len,
|
||||||
@@ -1352,13 +1354,13 @@ static int reduce_stack(struct rlimit *orig_rlim, char *argv[])
|
|||||||
|
|
||||||
error = setrlimit(RLIMIT_STACK, &new_rlim);
|
error = setrlimit(RLIMIT_STACK, &new_rlim);
|
||||||
if (error) {
|
if (error) {
|
||||||
__eprint("failed to setrlimit(RLIMIT_STACK)\n");
|
__eprintf("failed to setrlimit(RLIMIT_STACK)\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
execv("/proc/self/exe", argv);
|
execv("/proc/self/exe", argv);
|
||||||
|
|
||||||
__eprint("failed to execv(myself)\n");
|
__eprintf("failed to execv(myself)\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2103,7 +2105,7 @@ int main(int argc, char **argv)
|
|||||||
#endif /* ADD_ENVS_OPTION */
|
#endif /* ADD_ENVS_OPTION */
|
||||||
|
|
||||||
#ifdef ENABLE_MCOVERLAYFS
|
#ifdef ENABLE_MCOVERLAYFS
|
||||||
__dprint("mcoverlay enable\n");
|
__dprintf("mcoverlay enable\n");
|
||||||
char mcos_procdir[PATH_MAX];
|
char mcos_procdir[PATH_MAX];
|
||||||
char mcos_sysdir[PATH_MAX];
|
char mcos_sysdir[PATH_MAX];
|
||||||
|
|
||||||
@@ -2408,13 +2410,13 @@ int main(int argc, char **argv)
|
|||||||
dma_buf = mmap(0, PIN_SIZE, PROT_READ | PROT_WRITE,
|
dma_buf = mmap(0, PIN_SIZE, PROT_READ | PROT_WRITE,
|
||||||
(MAP_ANONYMOUS | MAP_PRIVATE), -1, 0);
|
(MAP_ANONYMOUS | MAP_PRIVATE), -1, 0);
|
||||||
if (dma_buf == (void *)-1) {
|
if (dma_buf == (void *)-1) {
|
||||||
__dprint("error: allocating DMA area\n");
|
__dprintf("error: allocating DMA area\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* PIN buffer */
|
/* PIN buffer */
|
||||||
if (mlock(dma_buf, (size_t)PIN_SIZE)) {
|
if (mlock(dma_buf, (size_t)PIN_SIZE)) {
|
||||||
__dprint("ERROR: locking dma_buf\n");
|
__dprintf("ERROR: locking dma_buf\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2456,7 +2458,7 @@ int main(int argc, char **argv)
|
|||||||
/* This call may not succeed, but that is fine */
|
/* This call may not succeed, but that is fine */
|
||||||
if (sched_setaffinity(0, sizeof(mcexec_cpu_set),
|
if (sched_setaffinity(0, sizeof(mcexec_cpu_set),
|
||||||
&mcexec_cpu_set) < 0) {
|
&mcexec_cpu_set) < 0) {
|
||||||
__dprint("WARNING: couldn't bind to mcexec_cpu_set\n");
|
__dprintf("WARNING: couldn't bind to mcexec_cpu_set\n");
|
||||||
}
|
}
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
else {
|
else {
|
||||||
@@ -2573,7 +2575,7 @@ int main(int argc, char **argv)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
__dprint("mccmd server initialized\n");
|
__dprintf("mccmd server initialized\n");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
init_sigaction();
|
init_sigaction();
|
||||||
@@ -3456,7 +3458,7 @@ int main_loop(struct thread_data_s *my_thread)
|
|||||||
dcfampi_cmd_server_exit();
|
dcfampi_cmd_server_exit();
|
||||||
#endif
|
#endif
|
||||||
mc_cmd_server_exit();
|
mc_cmd_server_exit();
|
||||||
__dprint("mccmd server exited\n");
|
__dprintf("mccmd server exited\n");
|
||||||
#endif
|
#endif
|
||||||
if(sig){
|
if(sig){
|
||||||
signal(sig, SIG_DFL);
|
signal(sig, SIG_DFL);
|
||||||
@@ -4400,6 +4402,6 @@ return_linux_spawn:
|
|||||||
|
|
||||||
//pthread_mutex_unlock(lock);
|
//pthread_mutex_unlock(lock);
|
||||||
}
|
}
|
||||||
__dprint("timed out.\n");
|
__dprintf("timed out.\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user