binutils-gdb/gdb/gdb.c
Tom de Vries c082d7f58e [gdb] Initialize main_thread_id earlier
I wrote a patch using is_main_thread (), and found it returning false in the
main thread due to main_thread_id not being initialized yet.

Initialization currently takes place in _initialize_run_on_main_thread, but
that's too late for earlier uses.

Fix this by initializing, either:
- when entering main, or
- on an earlier first use.

Tested on x86_64-linux.

Approved-By: Tom Tromey <tom@tromey.com>
2023-08-02 23:17:35 +02:00

41 lines
1.3 KiB
C

/* Main function for CLI gdb.
Copyright (C) 2002-2023 Free Software Foundation, Inc.
This file is part of GDB.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
#include "defs.h"
#include "main.h"
#include "interps.h"
#include "run-on-main-thread.h"
int
main (int argc, char **argv)
{
/* The first call to is_main_thread () should be from the main thread.
If this is the first call, then that requirement is fulfilled here.
If this is not the first call, then this verifies that the first call
fulfilled that requirement. */
gdb_assert (is_main_thread ());
struct captured_main_args args;
memset (&args, 0, sizeof args);
args.argc = argc;
args.argv = argv;
args.interpreter_p = INTERP_CONSOLE;
return gdb_main (&args);
}