VirtualBox

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

Last change on this file was 101035, checked in by vboxsync, 8 months ago

Initial commit (based draft v2 / on patch v5) for implementing platform architecture support for x86 and ARM. bugref:10384

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 25.1 KB
RevLine 
[1]1/* $Id: log-vbox.cpp 101035 2023-09-07 08:59:15Z vboxsync $ */
2/** @file
[19120]3 * VirtualBox Runtime - Logging configuration.
[1]4 */
5
6/*
[98103]7 * Copyright (C) 2006-2023 Oracle and/or its affiliates.
[1]8 *
[96407]9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.virtualbox.org.
[5999]11 *
[96407]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 *
[5999]25 * The contents of this file may alternatively be used under the terms
26 * of the Common Development and Distribution License Version 1.0
[96407]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
[5999]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.
[96407]33 *
34 * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
[1]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 *
[57974]85 * @section sec_logging_group The Group Specifier.
[1]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
[57358]136/*********************************************************************************************************************************
137* Header Files *
138*********************************************************************************************************************************/
[1]139#ifdef IN_RING3
[3672]140# if defined(RT_OS_WINDOWS)
[62592]141# include <iprt/win/windows.h>
[4555]142# elif defined(RT_OS_LINUX)
[95810]143# include <stdio.h>
[1]144# include <unistd.h>
[63189]145# elif defined(RT_OS_FREEBSD) || defined(RT_OS_NETBSD)
[25472]146# include <sys/param.h>
147# include <sys/sysctl.h>
[63189]148# if defined(RT_OS_FREEBSD)
149# include <sys/user.h>
150# endif
[25472]151# include <stdlib.h>
152# include <unistd.h>
[43363]153# elif defined(RT_OS_HAIKU)
154# include <OS.h>
[4555]155# elif defined(RT_OS_SOLARIS)
156# define _STRUCTURED_PROC 1
[4858]157# undef _FILE_OFFSET_BITS /* procfs doesn't like this */
[95810]158# include <stdio.h>
[4555]159# include <sys/procfs.h>
160# include <unistd.h>
[3672]161# elif defined(RT_OS_OS2)
[1]162# include <stdlib.h>
163# endif
164#endif
165
166#include <VBox/log.h>
167#include <iprt/asm.h>
[76452]168#include <iprt/errcore.h>
[1]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>
[25472]176# include <iprt/mem.h>
[95810]177# ifdef IPRT_NO_CRT
178# include <iprt/stream.h>
179# else
180# include <stdio.h>
181# endif
[1]182#endif
[48197]183#if defined(IN_RING0) && defined(RT_OS_DARWIN)
184# include <iprt/asm-amd64-x86.h>
185# include <iprt/thread.h>
186#endif
[1]187
188
[57358]189/*********************************************************************************************************************************
190* Global Variables *
191*********************************************************************************************************************************/
[1]192/** The default logger. */
[40938]193static PRTLOGGER g_pLogger = NULL;
[1]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.
[33540]209 * Take care to do this once and not recursively.
[1]210 */
211 static volatile uint32_t fInitializing = 0;
[7942]212 PRTLOGGER pLogger;
[18560]213 int rc;
[7942]214
[1]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)
[95810]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
[1]230 ASSERT_LOG_GROUP(DEFAULT);
[56648]231 ASSERT_LOG_GROUP(AUDIO_MIXER);
232 ASSERT_LOG_GROUP(AUDIO_MIXER_BUFFER);
[62894]233 ASSERT_LOG_GROUP(AUTOLOGON);
[1]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);
[62894]240 ASSERT_LOG_GROUP(DBGG);
[1]241 ASSERT_LOG_GROUP(DEV);
[56648]242 ASSERT_LOG_GROUP(DEV_AC97);
[1]243 ASSERT_LOG_GROUP(DEV_ACPI);
244 ASSERT_LOG_GROUP(DEV_APIC);
[62894]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);
[1]250 ASSERT_LOG_GROUP(DEV_FDC);
[62894]251 ASSERT_LOG_GROUP(DEV_GIM);
[56648]252 ASSERT_LOG_GROUP(DEV_HDA);
253 ASSERT_LOG_GROUP(DEV_HDA_CODEC);
[16065]254 ASSERT_LOG_GROUP(DEV_HPET);
[1]255 ASSERT_LOG_GROUP(DEV_IDE);
[62894]256 ASSERT_LOG_GROUP(DEV_INIP);
[1]257 ASSERT_LOG_GROUP(DEV_KBD);
[16170]258 ASSERT_LOG_GROUP(DEV_LPC);
[62894]259 ASSERT_LOG_GROUP(DEV_LSILOGICSCSI);
260 ASSERT_LOG_GROUP(DEV_NVME);
261 ASSERT_LOG_GROUP(DEV_OHCI);
262 ASSERT_LOG_GROUP(DEV_PARALLEL);
[1]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);
[62894]267 ASSERT_LOG_GROUP(DEV_PCI_RAW);
[1]268 ASSERT_LOG_GROUP(DEV_PCNET);
269 ASSERT_LOG_GROUP(DEV_PIC);
270 ASSERT_LOG_GROUP(DEV_PIT);
271 ASSERT_LOG_GROUP(DEV_RTC);
[56648]272 ASSERT_LOG_GROUP(DEV_SB16);
[1]273 ASSERT_LOG_GROUP(DEV_SERIAL);
[16065]274 ASSERT_LOG_GROUP(DEV_SMC);
[1]275 ASSERT_LOG_GROUP(DEV_VGA);
[62894]276 ASSERT_LOG_GROUP(DEV_VIRTIO);
277 ASSERT_LOG_GROUP(DEV_VIRTIO_NET);
[1]278 ASSERT_LOG_GROUP(DEV_VMM);
[62894]279 ASSERT_LOG_GROUP(DEV_VMM_BACKDOOR);
[1]280 ASSERT_LOG_GROUP(DEV_VMM_STDERR);
[62894]281 ASSERT_LOG_GROUP(DEV_VMSVGA);
282 ASSERT_LOG_GROUP(DEV_XHCI);
[1]283 ASSERT_LOG_GROUP(DIS);
284 ASSERT_LOG_GROUP(DRV);
285 ASSERT_LOG_GROUP(DRV_ACPI);
[56648]286 ASSERT_LOG_GROUP(DRV_AUDIO);
[1]287 ASSERT_LOG_GROUP(DRV_BLOCK);
[62894]288 ASSERT_LOG_GROUP(DRV_CHAR);
289 ASSERT_LOG_GROUP(DRV_DISK_INTEGRITY);
290 ASSERT_LOG_GROUP(DRV_DISPLAY);
[1]291 ASSERT_LOG_GROUP(DRV_FLOPPY);
[56648]292 ASSERT_LOG_GROUP(DRV_HOST_AUDIO);
[62894]293 ASSERT_LOG_GROUP(DRV_HOST_BASE);
[1]294 ASSERT_LOG_GROUP(DRV_HOST_DVD);
295 ASSERT_LOG_GROUP(DRV_HOST_FLOPPY);
[62894]296 ASSERT_LOG_GROUP(DRV_HOST_PARALLEL);
297 ASSERT_LOG_GROUP(DRV_HOST_SERIAL);
298 ASSERT_LOG_GROUP(DRV_INTNET);
[1]299 ASSERT_LOG_GROUP(DRV_ISO);
300 ASSERT_LOG_GROUP(DRV_KBD_QUEUE);
[62894]301 ASSERT_LOG_GROUP(DRV_LWIP);
302 ASSERT_LOG_GROUP(DRV_MINIPORT);
[1]303 ASSERT_LOG_GROUP(DRV_MOUSE_QUEUE);
[62894]304 ASSERT_LOG_GROUP(DRV_NAMEDPIPE);
[1]305 ASSERT_LOG_GROUP(DRV_NAT);
306 ASSERT_LOG_GROUP(DRV_RAW_IMAGE);
[62894]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);
[1]311 ASSERT_LOG_GROUP(DRV_TUN);
[62894]312 ASSERT_LOG_GROUP(DRV_UDPTUNNEL);
[1]313 ASSERT_LOG_GROUP(DRV_USBPROXY);
314 ASSERT_LOG_GROUP(DRV_VBOXHDD);
[62894]315 ASSERT_LOG_GROUP(DRV_VD);
[56648]316 ASSERT_LOG_GROUP(DRV_VRDE_AUDIO);
[1]317 ASSERT_LOG_GROUP(DRV_VSWITCH);
318 ASSERT_LOG_GROUP(DRV_VUSB);
319 ASSERT_LOG_GROUP(EM);
[62894]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);
[1]325 ASSERT_LOG_GROUP(GUI);
[62894]326 ASSERT_LOG_GROUP(GVMM);
[1]327 ASSERT_LOG_GROUP(HGCM);
[62894]328 ASSERT_LOG_GROUP(HGSMI);
[43387]329 ASSERT_LOG_GROUP(HM);
[62894]330 ASSERT_LOG_GROUP(IEM);
[100221]331 ASSERT_LOG_GROUP(IEM_RE_NATIVE);
332 ASSERT_LOG_GROUP(IEM_RE_THREADED);
333 ASSERT_LOG_GROUP(IEM_SVM);
334 ASSERT_LOG_GROUP(IEM_VMX);
[1]335 ASSERT_LOG_GROUP(IOM);
[62894]336 ASSERT_LOG_GROUP(IPC);
[50273]337 ASSERT_LOG_GROUP(LWIP);
[62894]338 ASSERT_LOG_GROUP(LWIP_API_LIB);
339 ASSERT_LOG_GROUP(LWIP_API_MSG);
340 ASSERT_LOG_GROUP(LWIP_ETHARP);
341 ASSERT_LOG_GROUP(LWIP_ICMP);
342 ASSERT_LOG_GROUP(LWIP_IGMP);
343 ASSERT_LOG_GROUP(LWIP_INET);
344 ASSERT_LOG_GROUP(LWIP_IP4);
345 ASSERT_LOG_GROUP(LWIP_IP4_REASS);
346 ASSERT_LOG_GROUP(LWIP_IP6);
347 ASSERT_LOG_GROUP(LWIP_MEM);
348 ASSERT_LOG_GROUP(LWIP_MEMP);
349 ASSERT_LOG_GROUP(LWIP_NETIF);
350 ASSERT_LOG_GROUP(LWIP_PBUF);
351 ASSERT_LOG_GROUP(LWIP_RAW);
352 ASSERT_LOG_GROUP(LWIP_SOCKETS);
353 ASSERT_LOG_GROUP(LWIP_SYS);
354 ASSERT_LOG_GROUP(LWIP_TCP);
355 ASSERT_LOG_GROUP(LWIP_TCPIP);
356 ASSERT_LOG_GROUP(LWIP_TCP_CWND);
357 ASSERT_LOG_GROUP(LWIP_TCP_FR);
358 ASSERT_LOG_GROUP(LWIP_TCP_INPUT);
359 ASSERT_LOG_GROUP(LWIP_TCP_OUTPUT);
360 ASSERT_LOG_GROUP(LWIP_TCP_QLEN);
361 ASSERT_LOG_GROUP(LWIP_TCP_RST);
362 ASSERT_LOG_GROUP(LWIP_TCP_RTO);
363 ASSERT_LOG_GROUP(LWIP_TCP_WND);
364 ASSERT_LOG_GROUP(LWIP_TIMERS);
365 ASSERT_LOG_GROUP(LWIP_UDP);
[1]366 ASSERT_LOG_GROUP(MAIN);
[62894]367 ASSERT_LOG_GROUP(MAIN_ADDITIONSFACILITY);
368 ASSERT_LOG_GROUP(MAIN_APPLIANCE);
369 ASSERT_LOG_GROUP(MAIN_AUDIOADAPTER);
370 ASSERT_LOG_GROUP(MAIN_BANDWIDTHCONTROL);
371 ASSERT_LOG_GROUP(MAIN_BANDWIDTHGROUP);
372 ASSERT_LOG_GROUP(MAIN_CONSOLE);
373 ASSERT_LOG_GROUP(MAIN_DHCPSERVER);
374 ASSERT_LOG_GROUP(MAIN_DIRECTORY);
375 ASSERT_LOG_GROUP(MAIN_DISPLAY);
376 ASSERT_LOG_GROUP(MAIN_DISPLAYSOURCEBITMAP);
377 ASSERT_LOG_GROUP(MAIN_DNDBASE);
378 ASSERT_LOG_GROUP(MAIN_DNDSOURCE);
379 ASSERT_LOG_GROUP(MAIN_DNDTARGET);
380 ASSERT_LOG_GROUP(MAIN_EMULATEDUSB);
381 ASSERT_LOG_GROUP(MAIN_EVENT);
382 ASSERT_LOG_GROUP(MAIN_EVENTLISTENER);
383 ASSERT_LOG_GROUP(MAIN_EVENTSOURCE);
384 ASSERT_LOG_GROUP(MAIN_EXTPACK);
385 ASSERT_LOG_GROUP(MAIN_EXTPACKBASE);
386 ASSERT_LOG_GROUP(MAIN_EXTPACKFILE);
387 ASSERT_LOG_GROUP(MAIN_EXTPACKMANAGER);
388 ASSERT_LOG_GROUP(MAIN_EXTPACKPLUGIN);
389 ASSERT_LOG_GROUP(MAIN_FILE);
[101035]390 ASSERT_LOG_GROUP(MAIN_FIRMWARESETTINGS);
[62894]391 ASSERT_LOG_GROUP(MAIN_FRAMEBUFFER);
392 ASSERT_LOG_GROUP(MAIN_FRAMEBUFFEROVERLAY);
393 ASSERT_LOG_GROUP(MAIN_FSOBJINFO);
394 ASSERT_LOG_GROUP(MAIN_GUEST);
395 ASSERT_LOG_GROUP(MAIN_GUESTDIRECTORY);
396 ASSERT_LOG_GROUP(MAIN_GUESTDNDSOURCE);
397 ASSERT_LOG_GROUP(MAIN_GUESTDNDTARGET);
398 ASSERT_LOG_GROUP(MAIN_GUESTERRORINFO);
399 ASSERT_LOG_GROUP(MAIN_GUESTFILE);
400 ASSERT_LOG_GROUP(MAIN_GUESTFSOBJINFO);
401 ASSERT_LOG_GROUP(MAIN_GUESTOSTYPE);
402 ASSERT_LOG_GROUP(MAIN_GUESTPROCESS);
403 ASSERT_LOG_GROUP(MAIN_GUESTSESSION);
404 ASSERT_LOG_GROUP(MAIN_HOST);
405 ASSERT_LOG_GROUP(MAIN_HOSTNETWORKINTERFACE);
406 ASSERT_LOG_GROUP(MAIN_HOSTUSBDEVICE);
407 ASSERT_LOG_GROUP(MAIN_HOSTUSBDEVICEFILTER);
408 ASSERT_LOG_GROUP(MAIN_HOSTVIDEOINPUTDEVICE);
409 ASSERT_LOG_GROUP(MAIN_INTERNALMACHINECONTROL);
410 ASSERT_LOG_GROUP(MAIN_INTERNALSESSIONCONTROL);
411 ASSERT_LOG_GROUP(MAIN_KEYBOARD);
412 ASSERT_LOG_GROUP(MAIN_MACHINE);
413 ASSERT_LOG_GROUP(MAIN_MACHINEDEBUGGER);
414 ASSERT_LOG_GROUP(MAIN_MEDIUM);
415 ASSERT_LOG_GROUP(MAIN_MEDIUMATTACHMENT);
416 ASSERT_LOG_GROUP(MAIN_MEDIUMFORMAT);
417 ASSERT_LOG_GROUP(MAIN_MOUSE);
418 ASSERT_LOG_GROUP(MAIN_MOUSEPOINTERSHAPE);
419 ASSERT_LOG_GROUP(MAIN_NATENGINE);
420 ASSERT_LOG_GROUP(MAIN_NATNETWORK);
421 ASSERT_LOG_GROUP(MAIN_NETWORKADAPTER);
422 ASSERT_LOG_GROUP(MAIN_PARALLELPORT);
423 ASSERT_LOG_GROUP(MAIN_PCIADDRESS);
424 ASSERT_LOG_GROUP(MAIN_PCIDEVICEATTACHMENT);
425 ASSERT_LOG_GROUP(MAIN_PERFORMANCECOLLECTOR);
426 ASSERT_LOG_GROUP(MAIN_PERFORMANCEMETRIC);
427 ASSERT_LOG_GROUP(MAIN_PROCESS);
428 ASSERT_LOG_GROUP(MAIN_PROGRESS);
429 ASSERT_LOG_GROUP(MAIN_SERIALPORT);
430 ASSERT_LOG_GROUP(MAIN_SESSION);
431 ASSERT_LOG_GROUP(MAIN_SHAREDFOLDER);
432 ASSERT_LOG_GROUP(MAIN_SNAPSHOT);
433 ASSERT_LOG_GROUP(MAIN_STORAGECONTROLLER);
434 ASSERT_LOG_GROUP(MAIN_SYSTEMPROPERTIES);
435 ASSERT_LOG_GROUP(MAIN_TOKEN);
436 ASSERT_LOG_GROUP(MAIN_USBCONTROLLER);
437 ASSERT_LOG_GROUP(MAIN_USBDEVICE);
438 ASSERT_LOG_GROUP(MAIN_USBDEVICEFILTERS);
439 ASSERT_LOG_GROUP(MAIN_VIRTUALBOX);
440 ASSERT_LOG_GROUP(MAIN_VIRTUALBOXCLIENT);
[66274]441 ASSERT_LOG_GROUP(MAIN_VIRTUALBOXSDS);
[62894]442 ASSERT_LOG_GROUP(MAIN_VIRTUALSYSTEMDESCRIPTION);
443 ASSERT_LOG_GROUP(MAIN_VRDESERVER);
444 ASSERT_LOG_GROUP(MAIN_VRDESERVERINFO);
445 ASSERT_LOG_GROUP(MISC);
[1]446 ASSERT_LOG_GROUP(MM);
447 ASSERT_LOG_GROUP(MM_HEAP);
448 ASSERT_LOG_GROUP(MM_HYPER);
449 ASSERT_LOG_GROUP(MM_HYPER_HEAP);
450 ASSERT_LOG_GROUP(MM_PHYS);
451 ASSERT_LOG_GROUP(MM_POOL);
[19315]452 ASSERT_LOG_GROUP(NAT_SERVICE);
[62894]453 ASSERT_LOG_GROUP(NET_ADP_DRV);
454 ASSERT_LOG_GROUP(NET_FLT_DRV);
[19315]455 ASSERT_LOG_GROUP(NET_SERVICE);
[62894]456 ASSERT_LOG_GROUP(NET_SHAPER);
[1]457 ASSERT_LOG_GROUP(PATM);
458 ASSERT_LOG_GROUP(PDM);
[62894]459 ASSERT_LOG_GROUP(PDM_ASYNC_COMPLETION);
460 ASSERT_LOG_GROUP(PDM_BLK_CACHE);
[1]461 ASSERT_LOG_GROUP(PDM_DEVICE);
462 ASSERT_LOG_GROUP(PDM_DRIVER);
463 ASSERT_LOG_GROUP(PDM_LDR);
464 ASSERT_LOG_GROUP(PDM_QUEUE);
465 ASSERT_LOG_GROUP(PGM);
[62894]466 ASSERT_LOG_GROUP(PGM_DYNMAP);
467 ASSERT_LOG_GROUP(PGM_PHYS);
468 ASSERT_LOG_GROUP(PGM_PHYS_ACCESS);
[1]469 ASSERT_LOG_GROUP(PGM_POOL);
[62894]470 ASSERT_LOG_GROUP(PGM_SHARED);
[1]471 ASSERT_LOG_GROUP(SELM);
[62894]472 ASSERT_LOG_GROUP(SHARED_CLIPBOARD);
473 ASSERT_LOG_GROUP(SHARED_CROPENGL);
474 ASSERT_LOG_GROUP(SHARED_FOLDERS);
475 ASSERT_LOG_GROUP(SHARED_OPENGL);
476 ASSERT_LOG_GROUP(SRV_INTNET);
[1]477 ASSERT_LOG_GROUP(SSM);
478 ASSERT_LOG_GROUP(STAM);
479 ASSERT_LOG_GROUP(SUP);
480 ASSERT_LOG_GROUP(TM);
481 ASSERT_LOG_GROUP(TRPM);
[62894]482 ASSERT_LOG_GROUP(USB_CARDREADER);
483 ASSERT_LOG_GROUP(USB_DRV);
484 ASSERT_LOG_GROUP(USB_FILTER);
485 ASSERT_LOG_GROUP(USB_KBD);
486 ASSERT_LOG_GROUP(USB_MOUSE);
487 ASSERT_LOG_GROUP(USB_MSD);
488 ASSERT_LOG_GROUP(USB_REMOTE);
489 ASSERT_LOG_GROUP(USB_WEBCAM);
[62895]490 ASSERT_LOG_GROUP(VGDRV);
[62894]491 ASSERT_LOG_GROUP(VBGL);
492 ASSERT_LOG_GROUP(VD);
493 ASSERT_LOG_GROUP(VD_DMG);
494 ASSERT_LOG_GROUP(VD_ISCSI);
495 ASSERT_LOG_GROUP(VD_PARALLELS);
496 ASSERT_LOG_GROUP(VD_QCOW);
497 ASSERT_LOG_GROUP(VD_QED);
498 ASSERT_LOG_GROUP(VD_RAW);
499 ASSERT_LOG_GROUP(VD_VDI);
500 ASSERT_LOG_GROUP(VD_VHD);
501 ASSERT_LOG_GROUP(VD_VHDX);
502 ASSERT_LOG_GROUP(VD_VMDK);
[1]503 ASSERT_LOG_GROUP(VM);
504 ASSERT_LOG_GROUP(VMM);
[62894]505 ASSERT_LOG_GROUP(VRDE);
[1]506 ASSERT_LOG_GROUP(VRDP);
[62894]507 ASSERT_LOG_GROUP(VSCSI);
508 ASSERT_LOG_GROUP(WEBSERVICE);
[1]509#undef ASSERT_LOG_GROUP
510#undef ASSERT_LOG_GROUP2
511#endif /* IN_RING3 */
512
513 /*
514 * Create the default logging instance.
515 */
516#ifdef IN_RING3
[83660]517 const char *pszExeName = RTProcShortName();
518 if (!pszExeName)
519 pszExeName = "VBox";
[1]520 RTTIMESPEC TimeSpec;
521 RTTIME Time;
[83663]522 RTPROCESS pid = RTProcSelf();
[1]523 RTTimeExplode(&Time, RTTimeNow(&TimeSpec));
[83660]524 rc = RTLogCreate(&pLogger, 0, NULL, "VBOX_LOG", RT_ELEMENTS(g_apszGroups), &g_apszGroups[0],
525# ifdef IN_GUEST
526 RTLOGDEST_USER /* backdoor */,
527 "./VBoxGAs-%04d-%02d-%02d-%02d-%02d-%02d.%03d-%s-%d.log",
528# else
529 RTLOGDEST_FILE,
[18560]530 "./%04d-%02d-%02d-%02d-%02d-%02d.%03d-%s-%d.log",
[83660]531# endif
532 Time.i32Year, Time.u8Month, Time.u8MonthDay, Time.u8Hour, Time.u8Minute, Time.u8Second,
[83663]533 Time.u32Nanosecond / 10000000, pszExeName, pid);
[1]534 if (RT_SUCCESS(rc))
535 {
536 /*
537 * Write a log header.
538 */
[83663]539 char szBuf[80];
540 RTPROCESS pidParent = NIL_RTPROCESS;
541 RTProcQueryParent(pid, &pidParent);
542 RTLogLoggerEx(pLogger, 0, ~0U,
543 "Log created: %s\n"
544 "Process ID: %d (%#x)\n"
545 "Parent PID: %d (%#x)\n"
546 "Executable: %s\n",
547 RTTimeSpecToString(&TimeSpec, szBuf, sizeof(szBuf)),
548 pid, pid,
549 pidParent, pidParent,
550 RTProcExecutablePath());
[1]551
552 /* executable and arguments - tricky and all platform specific. */
[83663]553# if defined(RT_OS_WINDOWS)
[1]554 RTLogLoggerEx(pLogger, 0, ~0U, "Commandline: %ls\n", GetCommandLineW());
555
[83663]556# elif defined(RT_OS_SOLARIS)
[4555]557 psinfo_t psi;
[83663]558 RTStrPrintf(szBuf, sizeof(szBuf), "/proc/%ld/psinfo", (long)getpid());
559 FILE *pFile = fopen(szBuf, "rb");
[4555]560 if (pFile)
561 {
562 if (fread(&psi, sizeof(psi), 1, pFile) == 1)
563 {
[83663]564# if 0 /* 100% safe:*/
[4555]565 RTLogLoggerEx(pLogger, 0, ~0U, "Args: %s\n", psi.pr_psargs);
[83663]566# else /* probably safe: */
[4555]567 const char * const *argv = (const char * const *)psi.pr_argv;
568 for (int iArg = 0; iArg < psi.pr_argc; iArg++)
569 RTLogLoggerEx(pLogger, 0, ~0U, "Arg[%d]: %s\n", iArg, argv[iArg]);
[83663]570# endif
[4555]571
572 }
573 fclose(pFile);
574 }
575
[83663]576# elif defined(RT_OS_LINUX)
[1]577 FILE *pFile = fopen("/proc/self/cmdline", "r");
578 if (pFile)
579 {
580 /* braindead */
581 unsigned iArg = 0;
[33664]582 int ch;
[1]583 bool fNew = true;
584 while (!feof(pFile) && (ch = fgetc(pFile)) != EOF)
585 {
586 if (fNew)
587 {
588 RTLogLoggerEx(pLogger, 0, ~0U, "Arg[%u]: ", iArg++);
589 fNew = false;
590 }
591 if (ch)
592 RTLogLoggerEx(pLogger, 0, ~0U, "%c", ch);
593 else
594 {
595 RTLogLoggerEx(pLogger, 0, ~0U, "\n");
596 fNew = true;
597 }
598 }
599 if (!fNew)
600 RTLogLoggerEx(pLogger, 0, ~0U, "\n");
601 fclose(pFile);
602 }
[25558]603
[83663]604# elif defined(RT_OS_HAIKU)
[43363]605 team_info info;
606 if (get_team_info(0, &info) == B_OK)
607 {
[45356]608 /* there is an info.argc, but no way to know arg boundaries */
[43363]609 RTLogLoggerEx(pLogger, 0, ~0U, "Commandline: %.64s\n", info.args);
610 }
611
[83663]612# elif defined(RT_OS_FREEBSD) || defined(RT_OS_NETBSD)
[25558]613 /* Retrieve the required length first */
[25472]614 int aiName[4];
[83663]615# if defined(RT_OS_FREEBSD)
[25472]616 aiName[0] = CTL_KERN;
617 aiName[1] = KERN_PROC;
[25558]618 aiName[2] = KERN_PROC_ARGS; /* Introduced in FreeBSD 4.0 */
619 aiName[3] = getpid();
[83663]620# elif defined(RT_OS_NETBSD)
[63189]621 aiName[0] = CTL_KERN;
622 aiName[1] = KERN_PROC_ARGS;
623 aiName[2] = getpid();
624 aiName[3] = KERN_PROC_ARGV;
[83663]625# endif
[25558]626 size_t cchArgs = 0;
[25472]627 int rcBSD = sysctl(aiName, RT_ELEMENTS(aiName), NULL, &cchArgs, NULL, 0);
628 if (cchArgs > 0)
629 {
[25558]630 char *pszArgFileBuf = (char *)RTMemAllocZ(cchArgs + 1 /* Safety */);
[25472]631 if (pszArgFileBuf)
632 {
633 /* Retrieve the argument list */
[25474]634 rcBSD = sysctl(aiName, RT_ELEMENTS(aiName), pszArgFileBuf, &cchArgs, NULL, 0);
[25472]635 if (!rcBSD)
636 {
[25558]637 unsigned iArg = 0;
638 size_t off = 0;
639 while (off < cchArgs)
[25472]640 {
[25558]641 size_t cchArg = strlen(&pszArgFileBuf[off]);
642 RTLogLoggerEx(pLogger, 0, ~0U, "Arg[%u]: %s\n", iArg, &pszArgFileBuf[off]);
643
644 /* advance */
645 off += cchArg + 1;
646 iArg++;
[25472]647 }
648 }
649 RTMemFree(pszArgFileBuf);
650 }
651 }
[25558]652
[83663]653# elif defined(RT_OS_OS2) || defined(RT_OS_DARWIN)
[1]654 /* commandline? */
[83663]655# else
656# error needs porting.
657# endif
[1]658 }
659
660#else /* IN_RING0 */
[48189]661
662 /* Some platforms has trouble allocating memory with interrupts and/or
663 preemption disabled. Check and fail before we panic. */
664# if defined(RT_OS_DARWIN)
665 if ( !ASMIntAreEnabled()
666 || !RTThreadPreemptIsEnabled(NIL_RTTHREAD))
667 return NULL;
668# endif
669
[21197]670# ifndef IN_GUEST
[40938]671 rc = RTLogCreate(&pLogger, 0, NULL, "VBOX_LOG", RT_ELEMENTS(g_apszGroups), &g_apszGroups[0], RTLOGDEST_FILE, "VBox-ring0.log");
[21197]672# else /* IN_GUEST */
[40938]673 rc = RTLogCreate(&pLogger, 0, NULL, "VBOX_LOG", RT_ELEMENTS(g_apszGroups), &g_apszGroups[0], RTLOGDEST_USER, "VBox-ring0.log");
[21197]674# endif /* IN_GUEST */
[1]675 if (RT_SUCCESS(rc))
676 {
677 /*
678 * This is where you set your ring-0 logging preferences.
[10608]679 *
680 * On platforms which don't differ between debugger and kernel
681 * log printing, STDOUT is gonna be a stub and the DEBUGGER
682 * destination is the one doing all the work. On platforms
683 * that do differ (like Darwin), STDOUT is the kernel log.
[1]684 */
[22479]685# if defined(DEBUG_bird)
686 /*RTLogGroupSettings(pLogger, "all=~0 -default.l6.l5.l4.l3");*/
[6543]687 RTLogFlags(pLogger, "enabled unbuffered pid tid");
[90829]688 RTLogDestinations(pLogger, "debugger stdout");
689# ifdef IN_GUEST
[78097]690 /*RTLogGroupSettings(pLogger, "all=~0 -default.l6.l5.l4.l3");*/
691 RTLogGroupSettings(pLogger, "all=~0");
[21197]692# endif
[1]693# endif
694# if defined(DEBUG_sandervl) && !defined(IN_GUEST)
695 RTLogGroupSettings(pLogger, "+all");
696 RTLogFlags(pLogger, "enabled unbuffered");
[90829]697 RTLogDestinations(pLogger, "debugger");
[1]698# endif
[6147]699# if defined(DEBUG_ramshankar) /* Guest ring-0 as well */
700 RTLogGroupSettings(pLogger, "+all.e.l.f");
701 RTLogFlags(pLogger, "enabled unbuffered");
[90829]702 RTLogDestinations(pLogger, "debugger");
[6147]703# endif
[14112]704# if defined(DEBUG_aleksey) /* Guest ring-0 as well */
[72261]705 RTLogGroupSettings(pLogger, "net_flt_drv.e.l.f.l3.l4.l5.l6 +net_adp_drv.e.l.f.l3.l4.l5.l6");
[13938]706 RTLogFlags(pLogger, "enabled unbuffered");
[90829]707 RTLogDestinations(pLogger, "debugger stdout");
[13938]708# endif
[26747]709# if defined(DEBUG_andy) /* Guest ring-0 as well */
710 RTLogGroupSettings(pLogger, "+all.e.l.f");
711 RTLogFlags(pLogger, "enabled unbuffered pid tid");
[90829]712 RTLogDestinations(pLogger, "debugger stdout");
[26747]713# endif
[34848]714# if defined(DEBUG_misha) /* Guest ring-0 as well */
[15773]715 RTLogFlags(pLogger, "enabled unbuffered");
[90829]716 RTLogDestinations(pLogger, "debugger");
[15773]717# endif
[48232]718# if defined(DEBUG_michael) && defined(IN_GUEST)
[59636]719 RTLogGroupSettings(pLogger, "+vga.e.l.f");
[36848]720 RTLogFlags(pLogger, "enabled unbuffered");
[90829]721 RTLogDestinations(pLogger, "debugger stdout");
[36848]722# endif
[33540]723# if 0 /* vboxdrv logging - ATTENTION: this is what we're referring to guys! Change to '# if 1'. */
[7013]724 RTLogGroupSettings(pLogger, "all=~0 -default.l6.l5.l4.l3");
725 RTLogFlags(pLogger, "enabled unbuffered tid");
[90829]726 RTLogDestinations(pLogger, "debugger stdout");
[7013]727# endif
[1]728 }
729#endif /* IN_RING0 */
[40938]730 return g_pLogger = RT_SUCCESS(rc) ? pLogger : NULL;
[1]731}
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use