VirtualBox

source: vbox/trunk/src/VBox/Runtime/VBox/log-vbox.cpp@ 98103

Last change on this file since 98103 was 98103, checked in by vboxsync, 16 months ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 25.2 KB
Line 
1/* $Id: log-vbox.cpp 98103 2023-01-17 14:15:46Z vboxsync $ */
2/** @file
3 * VirtualBox Runtime - Logging configuration.
4 */
5
6/*
7 * Copyright (C) 2006-2023 Oracle and/or its affiliates.
8 *
9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.virtualbox.org.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, in version 3 of the
15 * License.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <https://www.gnu.org/licenses>.
24 *
25 * The contents of this file may alternatively be used under the terms
26 * of the Common Development and Distribution License Version 1.0
27 * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
28 * in the VirtualBox distribution, in which case the provisions of the
29 * CDDL are applicable instead of those of the GPL.
30 *
31 * You may elect to license modified versions of this file under the
32 * terms and conditions of either the GPL or the CDDL or both.
33 *
34 * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
35 */
36
37/** @page pg_rtlog Runtime - Logging
38 *
39 * VBox uses the IPRT logging system which supports group level flags and multiple
40 * destinations. The GC logging is making it even more interesting since GC logging will
41 * have to be buffered and written when back in host context.
42 *
43 * [more later]
44 *
45 *
46 * @section sec_logging_destination The Destination Specifier.
47 *
48 * The {logger-env-base}_DEST environment variable can be used to specify where
49 * the log output goes. The following specifiers are recognized:
50 *
51 * - file=\<filename\>
52 * This sets the logger output filename to \<filename\>. Not formatting
53 * or anything is supported. Each logger specifies a default name if
54 * file logging should be enabled by default.
55 *
56 * - nofile
57 * This disables the file output.
58 *
59 * - stdout
60 * Enables logger output to stdout.
61 *
62 * - nostdout
63 * Disables logger output to stdout.
64 *
65 * - stderr
66 * Enables logger output to stderr.
67 *
68 * - nostderr
69 * Disables logger output to stderr.
70 *
71 * - debugger
72 * Enables logger output to native debugger. (Win32/64 only)
73 *
74 * - nodebugger
75 * Disables logger output to native debugger. (Win32/64 only)
76 *
77 * - user
78 * Enables logger output to special backdoor if in guest r0.
79 *
80 * - nodebugger
81 * Disables logger output to special user stream.
82 *
83 *
84 *
85 * @section sec_logging_group The Group Specifier.
86 *
87 * The {logger-env-base} environment variable can be used to specify which
88 * logger groups to enable and which to disable. By default all groups are
89 * disabled. For your convenience this specifier is case in-sensitive (ASCII).
90 *
91 * The specifier is evaluated from left to right.
92 *
93 * [more later]
94 *
95 * The groups settings can be reprogrammed during execution using the
96 * RTLogGroupSettings() command and a group specifier.
97 *
98 *
99 *
100 * @section sec_logging_default The Default Logger
101 *
102 * The default logger uses VBOX_LOG_DEST as destination specifier. File output is
103 * enabled by default and goes to a file "./VBox-\<pid\>.log".
104 *
105 * The default logger have all groups turned off by default to force the developer
106 * to be careful with what log information to collect - logging everything is
107 * generally NOT a good idea.
108 *
109 * The log groups of the default logger can be found in the LOGGROUP in enum. The
110 * VBOX_LOG environment variable and the .log debugger command can be used to
111 * configure the groups.
112 *
113 * Each group have flags in addition to the enable/disable flag. These flags can
114 * be appended to the group name using dot separators. The flags correspond to
115 * RTLOGGRPFLAGS and have a short and a long version:
116 *
117 * - e - Enabled: Whether the group is enabled at all.
118 * - l - Level2: Level-2 logging.
119 * - f - Flow: Execution flow logging (entry messages)
120 * - s - Sander: Special Sander logging messages.
121 * - b - Bird: Special Bird logging messages.
122 *
123 * @todo Update this section...
124 *
125 * Example:
126 *
127 * VBOX_LOG=+all+pgm.e.s.b.z.l-qemu
128 *
129 * Space and ';' separators are allowed:
130 *
131 * VBOX_LOG=+all +pgm.e.s.b.z.l ; - qemu
132 *
133 */
134
135
136/*********************************************************************************************************************************
137* Header Files *
138*********************************************************************************************************************************/
139#ifdef IN_RING3
140# if defined(RT_OS_WINDOWS)
141# include <iprt/win/windows.h>
142# elif defined(RT_OS_LINUX)
143# include <stdio.h>
144# include <unistd.h>
145# elif defined(RT_OS_FREEBSD) || defined(RT_OS_NETBSD)
146# include <sys/param.h>
147# include <sys/sysctl.h>
148# if defined(RT_OS_FREEBSD)
149# include <sys/user.h>
150# endif
151# include <stdlib.h>
152# include <unistd.h>
153# elif defined(RT_OS_HAIKU)
154# include <OS.h>
155# elif defined(RT_OS_SOLARIS)
156# define _STRUCTURED_PROC 1
157# undef _FILE_OFFSET_BITS /* procfs doesn't like this */
158# include <stdio.h>
159# include <sys/procfs.h>
160# include <unistd.h>
161# elif defined(RT_OS_OS2)
162# include <stdlib.h>
163# endif
164#endif
165
166#include <VBox/log.h>
167#include <iprt/asm.h>
168#include <iprt/errcore.h>
169#include <iprt/time.h>
170#ifdef IN_RING3
171# include <iprt/param.h>
172# include <iprt/assert.h>
173# include <iprt/path.h>
174# include <iprt/process.h>
175# include <iprt/string.h>
176# include <iprt/mem.h>
177# ifdef IPRT_NO_CRT
178# include <iprt/stream.h>
179# else
180# include <stdio.h>
181# endif
182#endif
183#if defined(IN_RING0) && defined(RT_OS_DARWIN)
184# include <iprt/asm-amd64-x86.h>
185# include <iprt/thread.h>
186#endif
187
188
189/*********************************************************************************************************************************
190* Global Variables *
191*********************************************************************************************************************************/
192/** The default logger. */
193static PRTLOGGER g_pLogger = NULL;
194/** The default logger groups.
195 * This must match LOGGROUP! */
196static const char *g_apszGroups[] =
197VBOX_LOGGROUP_NAMES;
198
199
200/**
201 * Creates the default logger instance for a VBox process.
202 *
203 * @returns Pointer to the logger instance.
204 */
205RTDECL(PRTLOGGER) RTLogDefaultInit(void)
206{
207 /*
208 * Initialize the default logger instance.
209 * Take care to do this once and not recursively.
210 */
211 static volatile uint32_t fInitializing = 0;
212 PRTLOGGER pLogger;
213 int rc;
214
215 if (g_pLogger || !ASMAtomicCmpXchgU32(&fInitializing, 1, 0))
216 return g_pLogger;
217
218#ifdef IN_RING3
219 /*
220 * Assert the group definitions.
221 */
222#define ASSERT_LOG_GROUP(grp) ASSERT_LOG_GROUP2(LOG_GROUP_##grp, #grp)
223#ifdef IPRT_NO_CRT
224# define ASSERT_LOG_GROUP2(def, str) \
225 do { if (strcmp(g_apszGroups[def], str)) { RTPrintf("%s='%s' expects '%s'\n", #def, g_apszGroups[def], str); RTAssertDoPanic(); } } while (0)
226# else
227# define ASSERT_LOG_GROUP2(def, str) \
228 do { if (strcmp(g_apszGroups[def], str)) { printf("%s='%s' expects '%s'\n", #def, g_apszGroups[def], str); RTAssertDoPanic(); } } while (0)
229# endif
230 ASSERT_LOG_GROUP(DEFAULT);
231 ASSERT_LOG_GROUP(AUDIO_MIXER);
232 ASSERT_LOG_GROUP(AUDIO_MIXER_BUFFER);
233 ASSERT_LOG_GROUP(AUTOLOGON);
234 ASSERT_LOG_GROUP(CFGM);
235 ASSERT_LOG_GROUP(CPUM);
236 ASSERT_LOG_GROUP(CSAM);
237 ASSERT_LOG_GROUP(DBGC);
238 ASSERT_LOG_GROUP(DBGF);
239 ASSERT_LOG_GROUP(DBGF_INFO);
240 ASSERT_LOG_GROUP(DBGG);
241 ASSERT_LOG_GROUP(DEV);
242 ASSERT_LOG_GROUP(DEV_AC97);
243 ASSERT_LOG_GROUP(DEV_ACPI);
244 ASSERT_LOG_GROUP(DEV_APIC);
245 ASSERT_LOG_GROUP(DEV_BUSLOGIC);
246 ASSERT_LOG_GROUP(DEV_DMA);
247 ASSERT_LOG_GROUP(DEV_E1000);
248 ASSERT_LOG_GROUP(DEV_EFI);
249 ASSERT_LOG_GROUP(DEV_EHCI);
250 ASSERT_LOG_GROUP(DEV_FDC);
251 ASSERT_LOG_GROUP(DEV_GIM);
252 ASSERT_LOG_GROUP(DEV_HDA);
253 ASSERT_LOG_GROUP(DEV_HDA_CODEC);
254 ASSERT_LOG_GROUP(DEV_HPET);
255 ASSERT_LOG_GROUP(DEV_IDE);
256 ASSERT_LOG_GROUP(DEV_INIP);
257 ASSERT_LOG_GROUP(DEV_KBD);
258 ASSERT_LOG_GROUP(DEV_LPC);
259 ASSERT_LOG_GROUP(DEV_LSILOGICSCSI);
260 ASSERT_LOG_GROUP(DEV_NVME);
261 ASSERT_LOG_GROUP(DEV_OHCI);
262 ASSERT_LOG_GROUP(DEV_PARALLEL);
263 ASSERT_LOG_GROUP(DEV_PC);
264 ASSERT_LOG_GROUP(DEV_PC_ARCH);
265 ASSERT_LOG_GROUP(DEV_PC_BIOS);
266 ASSERT_LOG_GROUP(DEV_PCI);
267 ASSERT_LOG_GROUP(DEV_PCI_RAW);
268 ASSERT_LOG_GROUP(DEV_PCNET);
269 ASSERT_LOG_GROUP(DEV_PIC);
270 ASSERT_LOG_GROUP(DEV_PIT);
271 ASSERT_LOG_GROUP(DEV_RTC);
272 ASSERT_LOG_GROUP(DEV_SB16);
273 ASSERT_LOG_GROUP(DEV_SERIAL);
274 ASSERT_LOG_GROUP(DEV_SMC);
275 ASSERT_LOG_GROUP(DEV_VGA);
276 ASSERT_LOG_GROUP(DEV_VIRTIO);
277 ASSERT_LOG_GROUP(DEV_VIRTIO_NET);
278 ASSERT_LOG_GROUP(DEV_VMM);
279 ASSERT_LOG_GROUP(DEV_VMM_BACKDOOR);
280 ASSERT_LOG_GROUP(DEV_VMM_STDERR);
281 ASSERT_LOG_GROUP(DEV_VMSVGA);
282 ASSERT_LOG_GROUP(DEV_XHCI);
283 ASSERT_LOG_GROUP(DIS);
284 ASSERT_LOG_GROUP(DRV);
285 ASSERT_LOG_GROUP(DRV_ACPI);
286 ASSERT_LOG_GROUP(DRV_AUDIO);
287 ASSERT_LOG_GROUP(DRV_BLOCK);
288 ASSERT_LOG_GROUP(DRV_CHAR);
289 ASSERT_LOG_GROUP(DRV_DISK_INTEGRITY);
290 ASSERT_LOG_GROUP(DRV_DISPLAY);
291 ASSERT_LOG_GROUP(DRV_FLOPPY);
292 ASSERT_LOG_GROUP(DRV_HOST_AUDIO);
293 ASSERT_LOG_GROUP(DRV_HOST_BASE);
294 ASSERT_LOG_GROUP(DRV_HOST_DVD);
295 ASSERT_LOG_GROUP(DRV_HOST_FLOPPY);
296 ASSERT_LOG_GROUP(DRV_HOST_PARALLEL);
297 ASSERT_LOG_GROUP(DRV_HOST_SERIAL);
298 ASSERT_LOG_GROUP(DRV_INTNET);
299 ASSERT_LOG_GROUP(DRV_ISO);
300 ASSERT_LOG_GROUP(DRV_KBD_QUEUE);
301 ASSERT_LOG_GROUP(DRV_LWIP);
302 ASSERT_LOG_GROUP(DRV_MINIPORT);
303 ASSERT_LOG_GROUP(DRV_MOUSE_QUEUE);
304 ASSERT_LOG_GROUP(DRV_NAMEDPIPE);
305 ASSERT_LOG_GROUP(DRV_NAT);
306 ASSERT_LOG_GROUP(DRV_RAW_IMAGE);
307 ASSERT_LOG_GROUP(DRV_SCSI);
308 ASSERT_LOG_GROUP(DRV_SCSIHOST);
309 ASSERT_LOG_GROUP(DRV_TCP);
310 ASSERT_LOG_GROUP(DRV_TRANSPORT_ASYNC);
311 ASSERT_LOG_GROUP(DRV_TUN);
312 ASSERT_LOG_GROUP(DRV_UDPTUNNEL);
313 ASSERT_LOG_GROUP(DRV_USBPROXY);
314 ASSERT_LOG_GROUP(DRV_VBOXHDD);
315 ASSERT_LOG_GROUP(DRV_VD);
316 ASSERT_LOG_GROUP(DRV_VRDE_AUDIO);
317 ASSERT_LOG_GROUP(DRV_VSWITCH);
318 ASSERT_LOG_GROUP(DRV_VUSB);
319 ASSERT_LOG_GROUP(EM);
320 ASSERT_LOG_GROUP(FTM);
321 ASSERT_LOG_GROUP(GIM);
322 ASSERT_LOG_GROUP(GMM);
323 ASSERT_LOG_GROUP(GUEST_CONTROL);
324 ASSERT_LOG_GROUP(GUEST_DND);
325 ASSERT_LOG_GROUP(GUI);
326 ASSERT_LOG_GROUP(GVMM);
327 ASSERT_LOG_GROUP(HGCM);
328 ASSERT_LOG_GROUP(HGSMI);
329 ASSERT_LOG_GROUP(HM);
330 ASSERT_LOG_GROUP(IEM);
331 ASSERT_LOG_GROUP(IOM);
332 ASSERT_LOG_GROUP(IPC);
333 ASSERT_LOG_GROUP(LWIP);
334 ASSERT_LOG_GROUP(LWIP_API_LIB);
335 ASSERT_LOG_GROUP(LWIP_API_MSG);
336 ASSERT_LOG_GROUP(LWIP_ETHARP);
337 ASSERT_LOG_GROUP(LWIP_ICMP);
338 ASSERT_LOG_GROUP(LWIP_IGMP);
339 ASSERT_LOG_GROUP(LWIP_INET);
340 ASSERT_LOG_GROUP(LWIP_IP4);
341 ASSERT_LOG_GROUP(LWIP_IP4_REASS);
342 ASSERT_LOG_GROUP(LWIP_IP6);
343 ASSERT_LOG_GROUP(LWIP_MEM);
344 ASSERT_LOG_GROUP(LWIP_MEMP);
345 ASSERT_LOG_GROUP(LWIP_NETIF);
346 ASSERT_LOG_GROUP(LWIP_PBUF);
347 ASSERT_LOG_GROUP(LWIP_RAW);
348 ASSERT_LOG_GROUP(LWIP_SOCKETS);
349 ASSERT_LOG_GROUP(LWIP_SYS);
350 ASSERT_LOG_GROUP(LWIP_TCP);
351 ASSERT_LOG_GROUP(LWIP_TCPIP);
352 ASSERT_LOG_GROUP(LWIP_TCP_CWND);
353 ASSERT_LOG_GROUP(LWIP_TCP_FR);
354 ASSERT_LOG_GROUP(LWIP_TCP_INPUT);
355 ASSERT_LOG_GROUP(LWIP_TCP_OUTPUT);
356 ASSERT_LOG_GROUP(LWIP_TCP_QLEN);
357 ASSERT_LOG_GROUP(LWIP_TCP_RST);
358 ASSERT_LOG_GROUP(LWIP_TCP_RTO);
359 ASSERT_LOG_GROUP(LWIP_TCP_WND);
360 ASSERT_LOG_GROUP(LWIP_TIMERS);
361 ASSERT_LOG_GROUP(LWIP_UDP);
362 ASSERT_LOG_GROUP(MAIN);
363 ASSERT_LOG_GROUP(MAIN_ADDITIONSFACILITY);
364 ASSERT_LOG_GROUP(MAIN_APPLIANCE);
365 ASSERT_LOG_GROUP(MAIN_AUDIOADAPTER);
366 ASSERT_LOG_GROUP(MAIN_BANDWIDTHCONTROL);
367 ASSERT_LOG_GROUP(MAIN_BANDWIDTHGROUP);
368 ASSERT_LOG_GROUP(MAIN_BIOSSETTINGS);
369 ASSERT_LOG_GROUP(MAIN_CONSOLE);
370 ASSERT_LOG_GROUP(MAIN_DHCPSERVER);
371 ASSERT_LOG_GROUP(MAIN_DIRECTORY);
372 ASSERT_LOG_GROUP(MAIN_DISPLAY);
373 ASSERT_LOG_GROUP(MAIN_DISPLAYSOURCEBITMAP);
374 ASSERT_LOG_GROUP(MAIN_DNDBASE);
375 ASSERT_LOG_GROUP(MAIN_DNDSOURCE);
376 ASSERT_LOG_GROUP(MAIN_DNDTARGET);
377 ASSERT_LOG_GROUP(MAIN_EMULATEDUSB);
378 ASSERT_LOG_GROUP(MAIN_EVENT);
379 ASSERT_LOG_GROUP(MAIN_EVENTLISTENER);
380 ASSERT_LOG_GROUP(MAIN_EVENTSOURCE);
381 ASSERT_LOG_GROUP(MAIN_EXTPACK);
382 ASSERT_LOG_GROUP(MAIN_EXTPACKBASE);
383 ASSERT_LOG_GROUP(MAIN_EXTPACKFILE);
384 ASSERT_LOG_GROUP(MAIN_EXTPACKMANAGER);
385 ASSERT_LOG_GROUP(MAIN_EXTPACKPLUGIN);
386 ASSERT_LOG_GROUP(MAIN_FILE);
387 ASSERT_LOG_GROUP(MAIN_FRAMEBUFFER);
388 ASSERT_LOG_GROUP(MAIN_FRAMEBUFFEROVERLAY);
389 ASSERT_LOG_GROUP(MAIN_FSOBJINFO);
390 ASSERT_LOG_GROUP(MAIN_GUEST);
391 ASSERT_LOG_GROUP(MAIN_GUESTDIRECTORY);
392 ASSERT_LOG_GROUP(MAIN_GUESTDNDSOURCE);
393 ASSERT_LOG_GROUP(MAIN_GUESTDNDTARGET);
394 ASSERT_LOG_GROUP(MAIN_GUESTERRORINFO);
395 ASSERT_LOG_GROUP(MAIN_GUESTFILE);
396 ASSERT_LOG_GROUP(MAIN_GUESTFSOBJINFO);
397 ASSERT_LOG_GROUP(MAIN_GUESTOSTYPE);
398 ASSERT_LOG_GROUP(MAIN_GUESTPROCESS);
399 ASSERT_LOG_GROUP(MAIN_GUESTSESSION);
400 ASSERT_LOG_GROUP(MAIN_HOST);
401 ASSERT_LOG_GROUP(MAIN_HOSTNETWORKINTERFACE);
402 ASSERT_LOG_GROUP(MAIN_HOSTUSBDEVICE);
403 ASSERT_LOG_GROUP(MAIN_HOSTUSBDEVICEFILTER);
404 ASSERT_LOG_GROUP(MAIN_HOSTVIDEOINPUTDEVICE);
405 ASSERT_LOG_GROUP(MAIN_INTERNALMACHINECONTROL);
406 ASSERT_LOG_GROUP(MAIN_INTERNALSESSIONCONTROL);
407 ASSERT_LOG_GROUP(MAIN_KEYBOARD);
408 ASSERT_LOG_GROUP(MAIN_MACHINE);
409 ASSERT_LOG_GROUP(MAIN_MACHINEDEBUGGER);
410 ASSERT_LOG_GROUP(MAIN_MEDIUM);
411 ASSERT_LOG_GROUP(MAIN_MEDIUMATTACHMENT);
412 ASSERT_LOG_GROUP(MAIN_MEDIUMFORMAT);
413 ASSERT_LOG_GROUP(MAIN_MOUSE);
414 ASSERT_LOG_GROUP(MAIN_MOUSEPOINTERSHAPE);
415 ASSERT_LOG_GROUP(MAIN_NATENGINE);
416 ASSERT_LOG_GROUP(MAIN_NATNETWORK);
417 ASSERT_LOG_GROUP(MAIN_NETWORKADAPTER);
418 ASSERT_LOG_GROUP(MAIN_PARALLELPORT);
419 ASSERT_LOG_GROUP(MAIN_PCIADDRESS);
420 ASSERT_LOG_GROUP(MAIN_PCIDEVICEATTACHMENT);
421 ASSERT_LOG_GROUP(MAIN_PERFORMANCECOLLECTOR);
422 ASSERT_LOG_GROUP(MAIN_PERFORMANCEMETRIC);
423 ASSERT_LOG_GROUP(MAIN_PROCESS);
424 ASSERT_LOG_GROUP(MAIN_PROGRESS);
425 ASSERT_LOG_GROUP(MAIN_SERIALPORT);
426 ASSERT_LOG_GROUP(MAIN_SESSION);
427 ASSERT_LOG_GROUP(MAIN_SHAREDFOLDER);
428 ASSERT_LOG_GROUP(MAIN_SNAPSHOT);
429 ASSERT_LOG_GROUP(MAIN_STORAGECONTROLLER);
430 ASSERT_LOG_GROUP(MAIN_SYSTEMPROPERTIES);
431 ASSERT_LOG_GROUP(MAIN_TOKEN);
432 ASSERT_LOG_GROUP(MAIN_USBCONTROLLER);
433 ASSERT_LOG_GROUP(MAIN_USBDEVICE);
434 ASSERT_LOG_GROUP(MAIN_USBDEVICEFILTERS);
435 ASSERT_LOG_GROUP(MAIN_VIRTUALBOX);
436 ASSERT_LOG_GROUP(MAIN_VIRTUALBOXCLIENT);
437 ASSERT_LOG_GROUP(MAIN_VIRTUALBOXSDS);
438 ASSERT_LOG_GROUP(MAIN_VIRTUALSYSTEMDESCRIPTION);
439 ASSERT_LOG_GROUP(MAIN_VRDESERVER);
440 ASSERT_LOG_GROUP(MAIN_VRDESERVERINFO);
441 ASSERT_LOG_GROUP(MISC);
442 ASSERT_LOG_GROUP(MM);
443 ASSERT_LOG_GROUP(MM_HEAP);
444 ASSERT_LOG_GROUP(MM_HYPER);
445 ASSERT_LOG_GROUP(MM_HYPER_HEAP);
446 ASSERT_LOG_GROUP(MM_PHYS);
447 ASSERT_LOG_GROUP(MM_POOL);
448 ASSERT_LOG_GROUP(NAT_SERVICE);
449 ASSERT_LOG_GROUP(NET_ADP_DRV);
450 ASSERT_LOG_GROUP(NET_FLT_DRV);
451 ASSERT_LOG_GROUP(NET_SERVICE);
452 ASSERT_LOG_GROUP(NET_SHAPER);
453 ASSERT_LOG_GROUP(PATM);
454 ASSERT_LOG_GROUP(PDM);
455 ASSERT_LOG_GROUP(PDM_ASYNC_COMPLETION);
456 ASSERT_LOG_GROUP(PDM_BLK_CACHE);
457 ASSERT_LOG_GROUP(PDM_DEVICE);
458 ASSERT_LOG_GROUP(PDM_DRIVER);
459 ASSERT_LOG_GROUP(PDM_LDR);
460 ASSERT_LOG_GROUP(PDM_QUEUE);
461 ASSERT_LOG_GROUP(PGM);
462 ASSERT_LOG_GROUP(PGM_DYNMAP);
463 ASSERT_LOG_GROUP(PGM_PHYS);
464 ASSERT_LOG_GROUP(PGM_PHYS_ACCESS);
465 ASSERT_LOG_GROUP(PGM_POOL);
466 ASSERT_LOG_GROUP(PGM_SHARED);
467 ASSERT_LOG_GROUP(REM);
468 ASSERT_LOG_GROUP(REM_DISAS);
469 ASSERT_LOG_GROUP(REM_HANDLER);
470 ASSERT_LOG_GROUP(REM_IOPORT);
471 ASSERT_LOG_GROUP(REM_MMIO);
472 ASSERT_LOG_GROUP(REM_PRINTF);
473 ASSERT_LOG_GROUP(REM_RUN);
474 ASSERT_LOG_GROUP(SELM);
475 ASSERT_LOG_GROUP(SHARED_CLIPBOARD);
476 ASSERT_LOG_GROUP(SHARED_CROPENGL);
477 ASSERT_LOG_GROUP(SHARED_FOLDERS);
478 ASSERT_LOG_GROUP(SHARED_OPENGL);
479 ASSERT_LOG_GROUP(SRV_INTNET);
480 ASSERT_LOG_GROUP(SSM);
481 ASSERT_LOG_GROUP(STAM);
482 ASSERT_LOG_GROUP(SUP);
483 ASSERT_LOG_GROUP(TM);
484 ASSERT_LOG_GROUP(TRPM);
485 ASSERT_LOG_GROUP(USB_CARDREADER);
486 ASSERT_LOG_GROUP(USB_DRV);
487 ASSERT_LOG_GROUP(USB_FILTER);
488 ASSERT_LOG_GROUP(USB_KBD);
489 ASSERT_LOG_GROUP(USB_MOUSE);
490 ASSERT_LOG_GROUP(USB_MSD);
491 ASSERT_LOG_GROUP(USB_REMOTE);
492 ASSERT_LOG_GROUP(USB_WEBCAM);
493 ASSERT_LOG_GROUP(VGDRV);
494 ASSERT_LOG_GROUP(VBGL);
495 ASSERT_LOG_GROUP(VD);
496 ASSERT_LOG_GROUP(VD_DMG);
497 ASSERT_LOG_GROUP(VD_ISCSI);
498 ASSERT_LOG_GROUP(VD_PARALLELS);
499 ASSERT_LOG_GROUP(VD_QCOW);
500 ASSERT_LOG_GROUP(VD_QED);
501 ASSERT_LOG_GROUP(VD_RAW);
502 ASSERT_LOG_GROUP(VD_VDI);
503 ASSERT_LOG_GROUP(VD_VHD);
504 ASSERT_LOG_GROUP(VD_VHDX);
505 ASSERT_LOG_GROUP(VD_VMDK);
506 ASSERT_LOG_GROUP(VM);
507 ASSERT_LOG_GROUP(VMM);
508 ASSERT_LOG_GROUP(VRDE);
509 ASSERT_LOG_GROUP(VRDP);
510 ASSERT_LOG_GROUP(VSCSI);
511 ASSERT_LOG_GROUP(WEBSERVICE);
512#undef ASSERT_LOG_GROUP
513#undef ASSERT_LOG_GROUP2
514#endif /* IN_RING3 */
515
516 /*
517 * Create the default logging instance.
518 */
519#ifdef IN_RING3
520 const char *pszExeName = RTProcShortName();
521 if (!pszExeName)
522 pszExeName = "VBox";
523 RTTIMESPEC TimeSpec;
524 RTTIME Time;
525 RTPROCESS pid = RTProcSelf();
526 RTTimeExplode(&Time, RTTimeNow(&TimeSpec));
527 rc = RTLogCreate(&pLogger, 0, NULL, "VBOX_LOG", RT_ELEMENTS(g_apszGroups), &g_apszGroups[0],
528# ifdef IN_GUEST
529 RTLOGDEST_USER /* backdoor */,
530 "./VBoxGAs-%04d-%02d-%02d-%02d-%02d-%02d.%03d-%s-%d.log",
531# else
532 RTLOGDEST_FILE,
533 "./%04d-%02d-%02d-%02d-%02d-%02d.%03d-%s-%d.log",
534# endif
535 Time.i32Year, Time.u8Month, Time.u8MonthDay, Time.u8Hour, Time.u8Minute, Time.u8Second,
536 Time.u32Nanosecond / 10000000, pszExeName, pid);
537 if (RT_SUCCESS(rc))
538 {
539 /*
540 * Write a log header.
541 */
542 char szBuf[80];
543 RTPROCESS pidParent = NIL_RTPROCESS;
544 RTProcQueryParent(pid, &pidParent);
545 RTLogLoggerEx(pLogger, 0, ~0U,
546 "Log created: %s\n"
547 "Process ID: %d (%#x)\n"
548 "Parent PID: %d (%#x)\n"
549 "Executable: %s\n",
550 RTTimeSpecToString(&TimeSpec, szBuf, sizeof(szBuf)),
551 pid, pid,
552 pidParent, pidParent,
553 RTProcExecutablePath());
554
555 /* executable and arguments - tricky and all platform specific. */
556# if defined(RT_OS_WINDOWS)
557 RTLogLoggerEx(pLogger, 0, ~0U, "Commandline: %ls\n", GetCommandLineW());
558
559# elif defined(RT_OS_SOLARIS)
560 psinfo_t psi;
561 RTStrPrintf(szBuf, sizeof(szBuf), "/proc/%ld/psinfo", (long)getpid());
562 FILE *pFile = fopen(szBuf, "rb");
563 if (pFile)
564 {
565 if (fread(&psi, sizeof(psi), 1, pFile) == 1)
566 {
567# if 0 /* 100% safe:*/
568 RTLogLoggerEx(pLogger, 0, ~0U, "Args: %s\n", psi.pr_psargs);
569# else /* probably safe: */
570 const char * const *argv = (const char * const *)psi.pr_argv;
571 for (int iArg = 0; iArg < psi.pr_argc; iArg++)
572 RTLogLoggerEx(pLogger, 0, ~0U, "Arg[%d]: %s\n", iArg, argv[iArg]);
573# endif
574
575 }
576 fclose(pFile);
577 }
578
579# elif defined(RT_OS_LINUX)
580 FILE *pFile = fopen("/proc/self/cmdline", "r");
581 if (pFile)
582 {
583 /* braindead */
584 unsigned iArg = 0;
585 int ch;
586 bool fNew = true;
587 while (!feof(pFile) && (ch = fgetc(pFile)) != EOF)
588 {
589 if (fNew)
590 {
591 RTLogLoggerEx(pLogger, 0, ~0U, "Arg[%u]: ", iArg++);
592 fNew = false;
593 }
594 if (ch)
595 RTLogLoggerEx(pLogger, 0, ~0U, "%c", ch);
596 else
597 {
598 RTLogLoggerEx(pLogger, 0, ~0U, "\n");
599 fNew = true;
600 }
601 }
602 if (!fNew)
603 RTLogLoggerEx(pLogger, 0, ~0U, "\n");
604 fclose(pFile);
605 }
606
607# elif defined(RT_OS_HAIKU)
608 team_info info;
609 if (get_team_info(0, &info) == B_OK)
610 {
611 /* there is an info.argc, but no way to know arg boundaries */
612 RTLogLoggerEx(pLogger, 0, ~0U, "Commandline: %.64s\n", info.args);
613 }
614
615# elif defined(RT_OS_FREEBSD) || defined(RT_OS_NETBSD)
616 /* Retrieve the required length first */
617 int aiName[4];
618# if defined(RT_OS_FREEBSD)
619 aiName[0] = CTL_KERN;
620 aiName[1] = KERN_PROC;
621 aiName[2] = KERN_PROC_ARGS; /* Introduced in FreeBSD 4.0 */
622 aiName[3] = getpid();
623# elif defined(RT_OS_NETBSD)
624 aiName[0] = CTL_KERN;
625 aiName[1] = KERN_PROC_ARGS;
626 aiName[2] = getpid();
627 aiName[3] = KERN_PROC_ARGV;
628# endif
629 size_t cchArgs = 0;
630 int rcBSD = sysctl(aiName, RT_ELEMENTS(aiName), NULL, &cchArgs, NULL, 0);
631 if (cchArgs > 0)
632 {
633 char *pszArgFileBuf = (char *)RTMemAllocZ(cchArgs + 1 /* Safety */);
634 if (pszArgFileBuf)
635 {
636 /* Retrieve the argument list */
637 rcBSD = sysctl(aiName, RT_ELEMENTS(aiName), pszArgFileBuf, &cchArgs, NULL, 0);
638 if (!rcBSD)
639 {
640 unsigned iArg = 0;
641 size_t off = 0;
642 while (off < cchArgs)
643 {
644 size_t cchArg = strlen(&pszArgFileBuf[off]);
645 RTLogLoggerEx(pLogger, 0, ~0U, "Arg[%u]: %s\n", iArg, &pszArgFileBuf[off]);
646
647 /* advance */
648 off += cchArg + 1;
649 iArg++;
650 }
651 }
652 RTMemFree(pszArgFileBuf);
653 }
654 }
655
656# elif defined(RT_OS_OS2) || defined(RT_OS_DARWIN)
657 /* commandline? */
658# else
659# error needs porting.
660# endif
661 }
662
663#else /* IN_RING0 */
664
665 /* Some platforms has trouble allocating memory with interrupts and/or
666 preemption disabled. Check and fail before we panic. */
667# if defined(RT_OS_DARWIN)
668 if ( !ASMIntAreEnabled()
669 || !RTThreadPreemptIsEnabled(NIL_RTTHREAD))
670 return NULL;
671# endif
672
673# ifndef IN_GUEST
674 rc = RTLogCreate(&pLogger, 0, NULL, "VBOX_LOG", RT_ELEMENTS(g_apszGroups), &g_apszGroups[0], RTLOGDEST_FILE, "VBox-ring0.log");
675# else /* IN_GUEST */
676 rc = RTLogCreate(&pLogger, 0, NULL, "VBOX_LOG", RT_ELEMENTS(g_apszGroups), &g_apszGroups[0], RTLOGDEST_USER, "VBox-ring0.log");
677# endif /* IN_GUEST */
678 if (RT_SUCCESS(rc))
679 {
680 /*
681 * This is where you set your ring-0 logging preferences.
682 *
683 * On platforms which don't differ between debugger and kernel
684 * log printing, STDOUT is gonna be a stub and the DEBUGGER
685 * destination is the one doing all the work. On platforms
686 * that do differ (like Darwin), STDOUT is the kernel log.
687 */
688# if defined(DEBUG_bird)
689 /*RTLogGroupSettings(pLogger, "all=~0 -default.l6.l5.l4.l3");*/
690 RTLogFlags(pLogger, "enabled unbuffered pid tid");
691 RTLogDestinations(pLogger, "debugger stdout");
692# ifdef IN_GUEST
693 /*RTLogGroupSettings(pLogger, "all=~0 -default.l6.l5.l4.l3");*/
694 RTLogGroupSettings(pLogger, "all=~0");
695# endif
696# endif
697# if defined(DEBUG_sandervl) && !defined(IN_GUEST)
698 RTLogGroupSettings(pLogger, "+all");
699 RTLogFlags(pLogger, "enabled unbuffered");
700 RTLogDestinations(pLogger, "debugger");
701# endif
702# if defined(DEBUG_ramshankar) /* Guest ring-0 as well */
703 RTLogGroupSettings(pLogger, "+all.e.l.f");
704 RTLogFlags(pLogger, "enabled unbuffered");
705 RTLogDestinations(pLogger, "debugger");
706# endif
707# if defined(DEBUG_aleksey) /* Guest ring-0 as well */
708 RTLogGroupSettings(pLogger, "net_flt_drv.e.l.f.l3.l4.l5.l6 +net_adp_drv.e.l.f.l3.l4.l5.l6");
709 RTLogFlags(pLogger, "enabled unbuffered");
710 RTLogDestinations(pLogger, "debugger stdout");
711# endif
712# if defined(DEBUG_andy) /* Guest ring-0 as well */
713 RTLogGroupSettings(pLogger, "+all.e.l.f");
714 RTLogFlags(pLogger, "enabled unbuffered pid tid");
715 RTLogDestinations(pLogger, "debugger stdout");
716# endif
717# if defined(DEBUG_misha) /* Guest ring-0 as well */
718 RTLogFlags(pLogger, "enabled unbuffered");
719 RTLogDestinations(pLogger, "debugger");
720# endif
721# if defined(DEBUG_michael) && defined(IN_GUEST)
722 RTLogGroupSettings(pLogger, "+vga.e.l.f");
723 RTLogFlags(pLogger, "enabled unbuffered");
724 RTLogDestinations(pLogger, "debugger stdout");
725# endif
726# if 0 /* vboxdrv logging - ATTENTION: this is what we're referring to guys! Change to '# if 1'. */
727 RTLogGroupSettings(pLogger, "all=~0 -default.l6.l5.l4.l3");
728 RTLogFlags(pLogger, "enabled unbuffered tid");
729 RTLogDestinations(pLogger, "debugger stdout");
730# endif
731 }
732#endif /* IN_RING0 */
733 return g_pLogger = RT_SUCCESS(rc) ? pLogger : NULL;
734}
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use