Command line support for altering the log file location
Add command line support for logging to a location other than /tmp/qemu.log. With logging enabled (command line option -d), the log is written to the hard-coded path /tmp/qemu.log. This patch adds support for writing the log to a different location by passing the -D option. Signed-off-by: Matthew Fernandez <matthew.fernandez@gmail.com> Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
This commit is contained in:
		
							parent
							
								
									71f34ad053
								
							
						
					
					
						commit
						c235d7387c
					
				|  | @ -690,7 +690,8 @@ static void usage(void) | ||||||
|            "-bsd type         select emulated BSD type FreeBSD/NetBSD/OpenBSD (default)\n" |            "-bsd type         select emulated BSD type FreeBSD/NetBSD/OpenBSD (default)\n" | ||||||
|            "\n" |            "\n" | ||||||
|            "Debug options:\n" |            "Debug options:\n" | ||||||
|            "-d options   activate log (logfile=%s)\n" |            "-d options   activate log (default logfile=%s)\n" | ||||||
|  |            "-D logfile   override default logfile location\n" | ||||||
|            "-p pagesize  set the host page size to 'pagesize'\n" |            "-p pagesize  set the host page size to 'pagesize'\n" | ||||||
|            "-singlestep  always run in singlestep mode\n" |            "-singlestep  always run in singlestep mode\n" | ||||||
|            "-strace      log system calls\n" |            "-strace      log system calls\n" | ||||||
|  | @ -731,6 +732,8 @@ int main(int argc, char **argv) | ||||||
| { | { | ||||||
|     const char *filename; |     const char *filename; | ||||||
|     const char *cpu_model; |     const char *cpu_model; | ||||||
|  |     const char *log_file = DEBUG_LOGFILE; | ||||||
|  |     const char *log_mask = NULL; | ||||||
|     struct target_pt_regs regs1, *regs = ®s1; |     struct target_pt_regs regs1, *regs = ®s1; | ||||||
|     struct image_info info1, *info = &info1; |     struct image_info info1, *info = &info1; | ||||||
|     TaskState ts1, *ts = &ts1; |     TaskState ts1, *ts = &ts1; | ||||||
|  | @ -745,9 +748,6 @@ int main(int argc, char **argv) | ||||||
|     if (argc <= 1) |     if (argc <= 1) | ||||||
|         usage(); |         usage(); | ||||||
| 
 | 
 | ||||||
|     /* init debug */ |  | ||||||
|     cpu_set_log_filename(DEBUG_LOGFILE); |  | ||||||
| 
 |  | ||||||
|     if ((envlist = envlist_create()) == NULL) { |     if ((envlist = envlist_create()) == NULL) { | ||||||
|         (void) fprintf(stderr, "Unable to allocate envlist\n"); |         (void) fprintf(stderr, "Unable to allocate envlist\n"); | ||||||
|         exit(1); |         exit(1); | ||||||
|  | @ -775,22 +775,15 @@ int main(int argc, char **argv) | ||||||
|         if (!strcmp(r, "-")) { |         if (!strcmp(r, "-")) { | ||||||
|             break; |             break; | ||||||
|         } else if (!strcmp(r, "d")) { |         } else if (!strcmp(r, "d")) { | ||||||
|             int mask; |             if (optind >= argc) { | ||||||
|             const CPULogItem *item; |  | ||||||
| 
 |  | ||||||
|             if (optind >= argc) |  | ||||||
|                 break; |                 break; | ||||||
| 
 |  | ||||||
|             r = argv[optind++]; |  | ||||||
|             mask = cpu_str_to_log_mask(r); |  | ||||||
|             if (!mask) { |  | ||||||
|                 printf("Log items (comma separated):\n"); |  | ||||||
|                 for(item = cpu_log_items; item->mask != 0; item++) { |  | ||||||
|                     printf("%-10s %s\n", item->name, item->help); |  | ||||||
|                 } |  | ||||||
|                 exit(1); |  | ||||||
|             } |             } | ||||||
|             cpu_set_log(mask); |             log_mask = argv[optind++]; | ||||||
|  |         } else if (!strcmp(r, "D")) { | ||||||
|  |             if (optind >= argc) { | ||||||
|  |                 break; | ||||||
|  |             } | ||||||
|  |             log_file = argv[optind++]; | ||||||
|         } else if (!strcmp(r, "E")) { |         } else if (!strcmp(r, "E")) { | ||||||
|             r = argv[optind++]; |             r = argv[optind++]; | ||||||
|             if (envlist_setenv(envlist, r) != 0) |             if (envlist_setenv(envlist, r) != 0) | ||||||
|  | @ -867,6 +860,23 @@ int main(int argc, char **argv) | ||||||
|         usage(); |         usage(); | ||||||
|     filename = argv[optind]; |     filename = argv[optind]; | ||||||
| 
 | 
 | ||||||
|  |     /* init debug */ | ||||||
|  |     cpu_set_log_filename(log_file); | ||||||
|  |     if (log_mask) { | ||||||
|  |         int mask; | ||||||
|  |         const CPULogItem *item; | ||||||
|  | 
 | ||||||
|  |         mask = cpu_str_to_log_mask(r); | ||||||
|  |         if (!mask) { | ||||||
|  |             printf("Log items (comma separated):\n"); | ||||||
|  |             for (item = cpu_log_items; item->mask != 0; item++) { | ||||||
|  |                 printf("%-10s %s\n", item->name, item->help); | ||||||
|  |             } | ||||||
|  |             exit(1); | ||||||
|  |         } | ||||||
|  |         cpu_set_log(mask); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     /* Zero out regs */ |     /* Zero out regs */ | ||||||
|     memset(regs, 0, sizeof(struct target_pt_regs)); |     memset(regs, 0, sizeof(struct target_pt_regs)); | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
							
								
								
									
										5
									
								
								cpus.c
								
								
								
								
							
							
						
						
									
										5
									
								
								cpus.c
								
								
								
								
							|  | @ -1142,6 +1142,11 @@ void set_cpu_log(const char *optarg) | ||||||
|     cpu_set_log(mask); |     cpu_set_log(mask); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | void set_cpu_log_filename(const char *optarg) | ||||||
|  | { | ||||||
|  |     cpu_set_log_filename(optarg); | ||||||
|  | } | ||||||
|  | 
 | ||||||
| /* Return the virtual CPU time, based on the instruction counter.  */ | /* Return the virtual CPU time, based on the instruction counter.  */ | ||||||
| int64_t cpu_get_icount(void) | int64_t cpu_get_icount(void) | ||||||
| { | { | ||||||
|  |  | ||||||
							
								
								
									
										1
									
								
								cpus.h
								
								
								
								
							
							
						
						
									
										1
									
								
								cpus.h
								
								
								
								
							|  | @ -19,6 +19,7 @@ void vm_state_notify(int running, int reason); | ||||||
| bool cpu_exec_all(void); | bool cpu_exec_all(void); | ||||||
| void set_numa_modes(void); | void set_numa_modes(void); | ||||||
| void set_cpu_log(const char *optarg); | void set_cpu_log(const char *optarg); | ||||||
|  | void set_cpu_log_filename(const char *optarg); | ||||||
| void list_cpus(FILE *f, fprintf_function cpu_fprintf, const char *optarg); | void list_cpus(FILE *f, fprintf_function cpu_fprintf, const char *optarg); | ||||||
| 
 | 
 | ||||||
| #endif | #endif | ||||||
|  |  | ||||||
|  | @ -738,6 +738,8 @@ TaskState *first_task_state; | ||||||
| int main(int argc, char **argv) | int main(int argc, char **argv) | ||||||
| { | { | ||||||
|     const char *filename; |     const char *filename; | ||||||
|  |     const char *log_file = DEBUG_LOGFILE; | ||||||
|  |     const char *log_mask = NULL; | ||||||
|     struct target_pt_regs regs1, *regs = ®s1; |     struct target_pt_regs regs1, *regs = ®s1; | ||||||
|     TaskState ts1, *ts = &ts1; |     TaskState ts1, *ts = &ts1; | ||||||
|     CPUState *env; |     CPUState *env; | ||||||
|  | @ -749,9 +751,6 @@ int main(int argc, char **argv) | ||||||
|     if (argc <= 1) |     if (argc <= 1) | ||||||
|         usage(); |         usage(); | ||||||
| 
 | 
 | ||||||
|     /* init debug */ |  | ||||||
|     cpu_set_log_filename(DEBUG_LOGFILE); |  | ||||||
| 
 |  | ||||||
|     optind = 1; |     optind = 1; | ||||||
|     for(;;) { |     for(;;) { | ||||||
|         if (optind >= argc) |         if (optind >= argc) | ||||||
|  | @ -764,22 +763,15 @@ int main(int argc, char **argv) | ||||||
|         if (!strcmp(r, "-")) { |         if (!strcmp(r, "-")) { | ||||||
|             break; |             break; | ||||||
|         } else if (!strcmp(r, "d")) { |         } else if (!strcmp(r, "d")) { | ||||||
|             int mask; |             if (optind >= argc) { | ||||||
|             CPULogItem *item; |                 break; | ||||||
| 
 |  | ||||||
|         if (optind >= argc) |  | ||||||
|         break; |  | ||||||
| 
 |  | ||||||
|         r = argv[optind++]; |  | ||||||
|             mask = cpu_str_to_log_mask(r); |  | ||||||
|             if (!mask) { |  | ||||||
|                 printf("Log items (comma separated):\n"); |  | ||||||
|                 for(item = cpu_log_items; item->mask != 0; item++) { |  | ||||||
|                     printf("%-10s %s\n", item->name, item->help); |  | ||||||
|                 } |  | ||||||
|                 exit(1); |  | ||||||
|             } |             } | ||||||
|             cpu_set_log(mask); |             log_mask = argv[optind++]; | ||||||
|  |         } else if (!strcmp(r, "D")) { | ||||||
|  |             if (optind >= argc) { | ||||||
|  |                 break; | ||||||
|  |             } | ||||||
|  |             log_file = argv[optind++]; | ||||||
|         } else if (!strcmp(r, "s")) { |         } else if (!strcmp(r, "s")) { | ||||||
|             r = argv[optind++]; |             r = argv[optind++]; | ||||||
|             stack_size = strtol(r, (char **)&r, 0); |             stack_size = strtol(r, (char **)&r, 0); | ||||||
|  | @ -821,6 +813,23 @@ int main(int argc, char **argv) | ||||||
|         usage(); |         usage(); | ||||||
|     filename = argv[optind]; |     filename = argv[optind]; | ||||||
| 
 | 
 | ||||||
|  |     /* init debug */ | ||||||
|  |     cpu_set_log_filename(log_file); | ||||||
|  |     if (log_mask) { | ||||||
|  |         int mask; | ||||||
|  |         CPULogItem *item; | ||||||
|  | 
 | ||||||
|  |         mask = cpu_str_to_log_mask(r); | ||||||
|  |         if (!mask) { | ||||||
|  |             printf("Log items (comma separated):\n"); | ||||||
|  |             for (item = cpu_log_items; item->mask != 0; item++) { | ||||||
|  |                 printf("%-10s %s\n", item->name, item->help); | ||||||
|  |             } | ||||||
|  |             exit(1); | ||||||
|  |         } | ||||||
|  |         cpu_set_log(mask); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     /* Zero out regs */ |     /* Zero out regs */ | ||||||
|     memset(regs, 0, sizeof(struct target_pt_regs)); |     memset(regs, 0, sizeof(struct target_pt_regs)); | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -2832,6 +2832,8 @@ int main(int argc, char **argv, char **envp) | ||||||
| { | { | ||||||
|     const char *filename; |     const char *filename; | ||||||
|     const char *cpu_model; |     const char *cpu_model; | ||||||
|  |     const char *log_file = DEBUG_LOGFILE; | ||||||
|  |     const char *log_mask = NULL; | ||||||
|     struct target_pt_regs regs1, *regs = ®s1; |     struct target_pt_regs regs1, *regs = ®s1; | ||||||
|     struct image_info info1, *info = &info1; |     struct image_info info1, *info = &info1; | ||||||
|     struct linux_binprm bprm; |     struct linux_binprm bprm; | ||||||
|  | @ -2853,9 +2855,6 @@ int main(int argc, char **argv, char **envp) | ||||||
| 
 | 
 | ||||||
|     qemu_cache_utils_init(envp); |     qemu_cache_utils_init(envp); | ||||||
| 
 | 
 | ||||||
|     /* init debug */ |  | ||||||
|     cpu_set_log_filename(DEBUG_LOGFILE); |  | ||||||
| 
 |  | ||||||
|     if ((envlist = envlist_create()) == NULL) { |     if ((envlist = envlist_create()) == NULL) { | ||||||
|         (void) fprintf(stderr, "Unable to allocate envlist\n"); |         (void) fprintf(stderr, "Unable to allocate envlist\n"); | ||||||
|         exit(1); |         exit(1); | ||||||
|  | @ -2894,22 +2893,15 @@ int main(int argc, char **argv, char **envp) | ||||||
|         if (!strcmp(r, "-")) { |         if (!strcmp(r, "-")) { | ||||||
|             break; |             break; | ||||||
|         } else if (!strcmp(r, "d")) { |         } else if (!strcmp(r, "d")) { | ||||||
|             int mask; |             if (optind >= argc) { | ||||||
|             const CPULogItem *item; |  | ||||||
| 
 |  | ||||||
| 	    if (optind >= argc) |  | ||||||
| 		break; | 		break; | ||||||
| 
 |  | ||||||
| 	    r = argv[optind++]; |  | ||||||
|             mask = cpu_str_to_log_mask(r); |  | ||||||
|             if (!mask) { |  | ||||||
|                 printf("Log items (comma separated):\n"); |  | ||||||
|                 for(item = cpu_log_items; item->mask != 0; item++) { |  | ||||||
|                     printf("%-10s %s\n", item->name, item->help); |  | ||||||
|                 } |  | ||||||
|                 exit(1); |  | ||||||
|             } |             } | ||||||
|             cpu_set_log(mask); |             log_mask = argv[optind++]; | ||||||
|  |         } else if (!strcmp(r, "D")) { | ||||||
|  |             if (optind >= argc) { | ||||||
|  |                 break; | ||||||
|  |             } | ||||||
|  |             log_file = argv[optind++]; | ||||||
|         } else if (!strcmp(r, "E")) { |         } else if (!strcmp(r, "E")) { | ||||||
|             r = argv[optind++]; |             r = argv[optind++]; | ||||||
|             if (envlist_setenv(envlist, r) != 0) |             if (envlist_setenv(envlist, r) != 0) | ||||||
|  | @ -3022,6 +3014,23 @@ int main(int argc, char **argv, char **envp) | ||||||
|     filename = argv[optind]; |     filename = argv[optind]; | ||||||
|     exec_path = argv[optind]; |     exec_path = argv[optind]; | ||||||
| 
 | 
 | ||||||
|  |     /* init debug */ | ||||||
|  |     cpu_set_log_filename(log_file); | ||||||
|  |     if (log_mask) { | ||||||
|  |         int mask; | ||||||
|  |         const CPULogItem *item; | ||||||
|  | 
 | ||||||
|  |         mask = cpu_str_to_log_mask(r); | ||||||
|  |         if (!mask) { | ||||||
|  |             printf("Log items (comma separated):\n"); | ||||||
|  |             for (item = cpu_log_items; item->mask != 0; item++) { | ||||||
|  |                 printf("%-10s %s\n", item->name, item->help); | ||||||
|  |             } | ||||||
|  |             exit(1); | ||||||
|  |         } | ||||||
|  |         cpu_set_log(mask); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     /* Zero out regs */ |     /* Zero out regs */ | ||||||
|     memset(regs, 0, sizeof(struct target_pt_regs)); |     memset(regs, 0, sizeof(struct target_pt_regs)); | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -2007,6 +2007,15 @@ STEXI | ||||||
| Output log in /tmp/qemu.log | Output log in /tmp/qemu.log | ||||||
| ETEXI | ETEXI | ||||||
| 
 | 
 | ||||||
|  | DEF("D", HAS_ARG, QEMU_OPTION_D, \ | ||||||
|  |     "-D logfile      output log to logfile (instead of the default /tmp/qemu.log)\n", | ||||||
|  |     QEMU_ARCH_ALL) | ||||||
|  | STEXI | ||||||
|  | @item -D | ||||||
|  | @findex -D | ||||||
|  | Output log in logfile instead of /tmp/qemu.log | ||||||
|  | ETEXI | ||||||
|  | 
 | ||||||
| DEF("hdachs", HAS_ARG, QEMU_OPTION_hdachs, \ | DEF("hdachs", HAS_ARG, QEMU_OPTION_hdachs, \ | ||||||
|     "-hdachs c,h,s[,t]\n" \ |     "-hdachs c,h,s[,t]\n" \ | ||||||
|     "                force hard disk 0 physical geometry and the optional BIOS\n" \ |     "                force hard disk 0 physical geometry and the optional BIOS\n" \ | ||||||
|  |  | ||||||
							
								
								
									
										19
									
								
								vl.c
								
								
								
								
							
							
						
						
									
										19
									
								
								vl.c
								
								
								
								
							|  | @ -2067,6 +2067,8 @@ int main(int argc, char **argv, char **envp) | ||||||
| #endif | #endif | ||||||
|     int defconfig = 1; |     int defconfig = 1; | ||||||
|     const char *trace_file = NULL; |     const char *trace_file = NULL; | ||||||
|  |     const char *log_mask = NULL; | ||||||
|  |     const char *log_file = NULL; | ||||||
| 
 | 
 | ||||||
|     atexit(qemu_run_exit_notifiers); |     atexit(qemu_run_exit_notifiers); | ||||||
|     error_set_progname(argv[0]); |     error_set_progname(argv[0]); | ||||||
|  | @ -2441,7 +2443,10 @@ int main(int argc, char **argv, char **envp) | ||||||
|                 break; |                 break; | ||||||
| #endif | #endif | ||||||
|             case QEMU_OPTION_d: |             case QEMU_OPTION_d: | ||||||
|                 set_cpu_log(optarg); |                 log_mask = optarg; | ||||||
|  |                 break; | ||||||
|  |             case QEMU_OPTION_D: | ||||||
|  |                 log_file = optarg; | ||||||
|                 break; |                 break; | ||||||
|             case QEMU_OPTION_s: |             case QEMU_OPTION_s: | ||||||
|                 gdbstub_dev = "tcp::" DEFAULT_GDBSTUB_PORT; |                 gdbstub_dev = "tcp::" DEFAULT_GDBSTUB_PORT; | ||||||
|  | @ -2907,6 +2912,18 @@ int main(int argc, char **argv, char **envp) | ||||||
|     } |     } | ||||||
|     loc_set_none(); |     loc_set_none(); | ||||||
| 
 | 
 | ||||||
|  |     /* Open the logfile at this point, if necessary. We can't open the logfile
 | ||||||
|  |      * when encountering either of the logging options (-d or -D) because the | ||||||
|  |      * other one may be encountered later on the command line, changing the | ||||||
|  |      * location or level of logging. | ||||||
|  |      */ | ||||||
|  |     if (log_mask) { | ||||||
|  |         if (log_file) { | ||||||
|  |             set_cpu_log_filename(log_file); | ||||||
|  |         } | ||||||
|  |         set_cpu_log(log_mask); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     if (!st_init(trace_file)) { |     if (!st_init(trace_file)) { | ||||||
|         fprintf(stderr, "warning: unable to initialize simple trace backend\n"); |         fprintf(stderr, "warning: unable to initialize simple trace backend\n"); | ||||||
|     } |     } | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	 Matthew Fernandez
						Matthew Fernandez