How to debug cef code?

Do not post support requests, bug reports or feature requests. Discuss CEF here. Non-CEF related discussion goes in General Discussion!

How to debug cef code?

Postby alice0 » Fri Dec 06, 2024 3:19 am

How to debug cef code?
I add some print but it can't see the message on anywhere


I want to print the string like this
```
CefRefPtr<CefApp> app;
switch (shared::GetProcessType(command_line)) {
case shared::PROCESS_TYPE_BROWSER:
app = shared::CreateBrowserProcessApp();
std::cout << " PROCESS_TYPE_BROWSER " << std::endl;
break;
case shared::PROCESS_TYPE_RENDERER:
app = shared::CreateRendererProcessApp();
std::cout << " PROCESS_TYPE_RENDERER " << std::endl;

break;
case shared::PROCESS_TYPE_OTHER:
app = shared::CreateOtherProcessApp();
std::cout << " PROCESS_TYPE_OTHER " << std::endl;

break;
}
```
alice0
Techie
 
Posts: 17
Joined: Fri Nov 22, 2024 3:01 am

Re: How to debug cef code?

Postby ndesktop » Fri Dec 06, 2024 6:24 am

Run it with --enable-logging --v=1 (0, 2, ... ) from command line.
More details on CEF wiki, peter.sh website and Chromium source.
ndesktop
Master
 
Posts: 907
Joined: Thu Dec 03, 2015 10:10 am

Re: How to debug cef code?

Postby alice0 » Tue Dec 10, 2024 7:49 pm

What is the code to replace std::cout << "hi" << std::endl ?
I open the --enable-logging mode and it doesn't show the message for std::cout .

Maybe it use the LOG, but I don't still see any log on my console.
What does I miss?

```
// Main program entry point function.
int APIENTRY wWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow) {
UNREFERENCED_PARAMETER(hPrevInstance);
UNREFERENCED_PARAMETER(lpCmdLine);
UNREFERENCED_PARAMETER(nCmdShow);
void* sandbox_info = nullptr;

#if defined(CEF_USE_SANDBOX)
// Manage the life span of the sandbox information object. This is necessary
// for sandbox support on Windows. See cef_sandbox_win.h for complete details.
CefScopedSandboxInfo scoped_sandbox;
sandbox_info = scoped_sandbox.sandbox_info();
#endif

LOG(INFO) << "hahahahahahahahah";
DLOG(INFO) << "hohohohohoho debug";

// Provide CEF with command-line arguments.
CefMainArgs main_args(hInstance);

// Create a temporary CommandLine object.
CefRefPtr<CefCommandLine> command_line = shared::CreateCommandLine(main_args);
```


.\resource_manager.exe --enable-logging

[112944:161236:1211/095330.556:ERROR:gpu_process_host.cc(980)] GPU process exited unexpectedly: exit_code=-2147483645
[112944:161236:1211/095330.708:ERROR:gpu_process_host.cc(980)] GPU process exited unexpectedly: exit_code=-2147483645
[112944:161236:1211/095330.871:ERROR:gpu_process_host.cc(980)] GPU process exited unexpectedly: exit_code=-2147483645
alice0
Techie
 
Posts: 17
Joined: Fri Nov 22, 2024 3:01 am

Re: How to debug cef code?

Postby magreenblatt » Tue Dec 10, 2024 9:38 pm

Logging won't be configurable until after CefInitialize is called. The default log level is WARNING, so use LOG(WARNING) or LOG(ERROR).
magreenblatt
Site Admin
 
Posts: 13006
Joined: Fri May 29, 2009 6:57 pm

Re: How to debug cef code?

Postby ndesktop » Wed Dec 11, 2024 3:25 am

Also, although unsupported (and crashing on exit), one can launch the application with --single-process from the debugger. Although this will push the machine to the limit because of the very large symbol file size.
ndesktop
Master
 
Posts: 907
Joined: Thu Dec 03, 2015 10:10 am

Re: How to debug cef code?

Postby alice0 » Wed Dec 11, 2024 10:11 pm

I try to use cef-project and add LOG command on main_win.cc

```
#if !defined(CEF_USE_SANDBOX)
settings.no_sandbox = true;
#endif

// Initialize the CEF browser process. The first browser instance will be
// created in CefBrowserProcessHandler::OnContextInitialized() after CEF has
// been initialized. May return false if initialization fails or if early exit
// is desired (for example, due to process singleton relaunch behavior).
if (!CefInitialize(main_args, settings, app, sandbox_info)) {
return 1;
}

DLOG(WARNING) << "PROCESS_TYPE_BROWSER debug";
LOG(WARNING) << "PROCESS_TYPE_BROWSER";
DLOG(INFO) << "PROCESS_TYPE_BROWSER debug";
LOG(INFO) << "PROCESS_TYPE_BROWSER";
DLOG(WARNING) << "PROCESS_TYPE_BROWSER debug";
LOG(WARNING) << "PROCESS_TYPE_BROWSER";
PLOG(ERROR) << "Couldn't do foo";
// Run the CEF message loop. This will block until CefQuitMessageLoop() is
// called.
CefRunMessageLoop();
DLOG(WARNING) << "PROCESS_TYPE_BROWSER debug";
LOG(WARNING) << "PROCESS_TYPE_BROWSER";
// Shut down CEF.
CefShutdown();

return 0;
}

```

And then go to build folder and open command prompt
```
.\resource_manager.exe --enable-logging
```


No log on command prompt for resource_manager project
I use error warning info and all is not work.
What happen?


I use windows 11 and visual studio to build.




I found the problem that LOG(WARNING) is not work.
Only LOG(ERROR) and DLOG(ERROR) can work when .\resource_manager.exe --enable-logging
What should I control it to show warning and info
Last edited by alice0 on Wed Dec 11, 2024 10:24 pm, edited 2 times in total.
alice0
Techie
 
Posts: 17
Joined: Fri Nov 22, 2024 3:01 am

Re: How to debug cef code?

Postby magreenblatt » Wed Dec 11, 2024 10:13 pm

magreenblatt
Site Admin
 
Posts: 13006
Joined: Fri May 29, 2009 6:57 pm


Return to CEF Discussion

Who is online

Users browsing this forum: Google [Bot] and 10 guests