Getting gdb to automatically load binary from core file - c++

Can I get gdb to automatically load the binary that's specified in the core file?
Given a core file I now usually do:
gdb -c corefile
GNU gdb 6.8
...
Core was generated by `/path/to/binary'
Then i copy-paste that and run:
gdb -c corefile /path/to/binary
It seems like an unnecessary two-step process and yet I don't seen an obvious way of doing it based on the man page. Am I missing something?

You could just script it?
#!/bin/bash
gdb "`file "$1" | awk -F \' '{print $2}'`" "$1"

This is what I usually endup doing:
var=$(file corefile)
echo ${var##*from}

gdc() {
gdb -c "$1" "$(file "$1" | sed -r -e "s#.*execfn: '([^\']+)'.*#\1#")"
}
$ gdc corefile

Related

Passing valgrind flags from cmake

Complementary to this question, how can I pass flags to valgrind from cmake?
# enable valgrind checks
set(CTEST_MEMORYCHECK_TYPE "valgrind")
set(CTEST_MEMORYCHECK_COMMAND_OPTIONS "--leak-check=no")
According to the docs, The lines above should work, but after running cmake . + make I get:
$ ctest -T memcheck | grep "Memory Leak\|Defects"
1/1 MemCheck: #1: test ............................. Defects: 1
Memory Leak - 1
When I inspect the DartConfiguration.tcl file I don't see my flag there:
$ sed -n "79,80p" ./DartConfiguration.tcl
MemoryCheckCommand: /usr/local/bin/valgrind
MemoryCheckCommandOptions: # <--- nothing here ...
After manually editing DartConfiguration.tcl everything works fine:
$ sed -i "s/MemoryCheckCommandOptions:/MemoryCheckCommandOptions: --leak-check=no/g" DartConfiguration.tcl
$ ctest -T memcheck | grep "Memory Leak\|Defects"
$ # nothing ( good )
All the details exist in the public repo: https://github.com/OrenGitHub/ValgrindCmake
Particularly, the cmake test pipelines: here and here

how to hold xterm during debugging an mpi program?

I run the debugger via
mpirun -n 4 xterm -e gdb -x commands.gdb ./my_mpi_programm
where the file "commands.gdb" just contains the commands
start
continue
The problem is that my 4 xterm immediately close before I get a chance to inspect the error message or do any debugging.
I'm using the latest ubuntu distribution. However, on my friend's old Suse-distribution, xterm is held open.
How can I force the xterms to stay?
EDIT: the "-hold" option doesnt work as well as
mpirun -n 4 xterm -e "gdb -x commands.gdb ./my_mpi_programm;bash"
Try
mpirun -n 4 xterm -e bash -c 'gdb -x commands.gdb ./my_mpi_programm; sleep 60'

Pass a regex pattern to Perl Packer from Powershell

How do I correctly write this in a Windows Powershell? Coming from macOS, I have some problems in understanding what it is wrong with this:
pp -u -g -o Executable -f Bleach="^(AAA_|BBB_|MainScript)" MainScript.pl
The regular expression to be passed to the option -f (filter) is not accepted and fires all sort of errors (command not recognized, and so on, no matter as I try to change it). On a Unix system it works just fine.
Escape character for Powershell is `.
Something like this could work:
pp -u -g -o Executable -f Bleach=`"`(AAA_`|BBB_`|MainScript`)`" MainScript.pl`

**/*.java not working as argument to Bash script

I have a simple bash script file named: test.sh.
#!/bin/bash
ls $1;
I gave the execution permissions:
$ ./test.sh "**/*.java"
shows only one file
where as
$ ls **/*.java
shows hundreds of files
So how to make the script work.
To enable support for ** in Bash, use the globstar option:
#!/bin/bash
shopt -s globstar
ls $1
(See ยง4.3.2 "The Shopt Builtin" in the Bash Reference Manual.)

Why is my gdb debugger setting 2 break points?

Is this normal? I swear it was setting only 1 break point until recently. How do I make it only set a breakpoint in my running file and not the source file.
(gdb) break main
Breakpoint 1 at 0x1dbf
Breakpoint 2 at 0x1ed8: file arrays.c, line 17.
warning: Multiple breakpoints were set.
Use the "delete" command to delete unwanted breakpoints.
(gdb)
There are multiple main symbols :) Perhaps look at 'info breakpoints' in gdb or
objdump -C -t myprog
to see why/where.
Use cscope to interactively search for declarations.
ctags -R . && grep -w main tags
[ -x /usr/bin/vim ] && vim +'tj main'
Should be helpful as well if you have ctags (and optionally, vim) installed
If all else fails, brute force grep -RIw main . should work. If even that fails, you should find yourself with very strange external header #defines or even a (static) library with a surplus main symbol. To brute force search for the main identifier through the preprocessed sources:
find -name '*.c' -print0 | xargs -0n1 -iQ cpp -I/usr/include/... -DDEBUG Q Q.ii
find -name '*.c.ii' -print0 | xargs grep -wI main
(replace -I/usr/include/... -DDEBUG with the relevant preprocessor defines)