How to define alias for gdb function - gdb

GDB supports function by command define. I want to write a helper script for GDB, and I hope each function has a meaningful name and an alias, just like bt and backtrace.
Does GDB support this feature?

An example to complete matt's answer:
alias ir = info registers
ir
as documented at: https://sourceware.org/gdb/onlinedocs/gdb/Aliases.html
Unlike Bash aliases, you cannot pass arguments to the definition of those aliases, e.g.:
alias ir = info registers eax
The registers part is only accepted because it is not an argument, but a subcommand.
But you can pass arguments when using the alias:
ir eax
You can then list all currently defined aliases with:
help aliases

(gdb) apropos alias
alias -- Alias one command to another
aliases -- Aliases of other commands

Related

Why does gdb show a different parameter order for a function

Looking through a core file(generated by C code) with gdb, I am unable to understand one particular thing between these 2 frames
#2 increment_counter (nsteps=2, steps=0x7f3fbad26790) at gconv_db.c:393
#3 find_derivation (...) at gconv_db.c:426
This code is from open source glibc where find_derivation calls increment_counter as:
result = increment_counter (*handle, *nsteps);
The *handle and steps are of the same type and increment_counter function is defined as static
Why does gdb show that the 2 parameters have different order ?
I am pretty sure that glibc was taken as is without modification
Why does gdb show that the 2 parameters have different order ?
GDB doesn't know anything about the source (except possibly where on disk it was located at build time).
It is able to display parameters (and their values) because the compiler told it (by embedding debug info into the object file) what parameters are, in what order they appear, their types, and how to compute their value.
So why would a compiler re-order function arguments?
The function is static, so it can't be called from outside of the current translation unit. Thus the compiler is free to re-order the parameters, so long as it also re-orders the arguments at every call site.
Still, why would it do that? General answer: optimization (compiler found it more convenient to pass them in this order). Detailed answer would require digging into GCC (or whatever compiler was used to build this code) source.

gdb can't call function

I have some problems with debugging my app - when I try to call parser::extractString(...) from gdb shell it return
No symbol "extractString" in namespace "parser".
When I execute
info functions extractString
I have this output
All functions matching regular expression "extractString":
File /home/dmitriy/Sources/transceiver/parser/json.cpp:
std::__cxx11::string
parser::extractString[abi:cxx11](rapidjson::GenericValue,
parser::MultithreadAllocator> const&);
Non-debugging symbols: 0x0000000000506500
parser::extractString[abi:cxx11](rapidjson::GenericValue,
parser::MultithreadAllocator> const&)#plt 0x00007ffff77e3640
parser::extractString[abi:cxx11](rapidjson::GenericValue,
parser::MultithreadAllocator> const&)#plt
What is the problem with calling this function? Function extractString defined in static library and called from the application without any problem.
gdb does not yet support C++11 ABI tags introduced in gcc 5. See these bugs:
https://sourceware.org/bugzilla/show_bug.cgi?id=19436
https://sourceware.org/bugzilla/show_bug.cgi?id=18601
The simplest workaround for you is probably to disable new gcc ABI by defining the macro _GLIBCXX_USE_CXX11_ABI to 0, see https://gcc.gnu.org/gcc-5/changes.html#libstdcxx.
Or alternatively you can try to apply workarounds from https://sourceware.org/bugzilla/show_bug.cgi?id=18601#c1 though they look a bit weird.

Create a custom name for an address in gdb?

I'm reverse engineering a program using gdb and I'm getting confused in all the addresses I enter to various commands. Is there a way to create (and store) a custom variable so that I could say x/i my_addr_name instead of x/i 0xdeadbeef?
gdb has user-definable convenience variables to hold various values.
(gdb) set $my_addr_name=$pc
(gdb) x/i $my_addr_name
=> 0x400c7d <main+390>: lea -0xa0(%rbp),%rax
(gdb) ptype $my_addr_name
type = void (*)()
Convenience variable have a type, and the print command will make use of that, but the x command uses explicit or default formats and doesn't take the type of the expression into account.
could I have x/i 0xdeadbeff say my_addr_name+16
I don't think so, unless some additional C or python code is written. gdb's C source code has a build_address_symbolic function, which looks through the symbol tables to find the symbol nearest to an address. Short of creating a custom symbol table, then loading it with the add-symbol-file command, or writing a python extension to implement an alternative to the x command, I don't think such a customization is possible, currently.

Vim Ctags how to auto complete function arguments?

I'm wondering if it's possible or not to auto complete function arguments from tags generated by exuberant ctags? I noticed that when I generate a tag, I see the function argument WITH the function, so it would be logical to assume that it's possible to complete the arguments.
I'm familiar that there are alternatives such as clang_complete and youcompleteme, which uses the clang compiler, but that's an added dependency. I'm already using Tagbar + EasyTags, etc, so why not just use tags if it's already there, than to bloat up vim.
It's not really "completion" of the function arguments, but from the comments on your question you said you want a guide to what arguments a function takes after doing tag completion.
If your completion method supports it, you can see such a guide with :set completeopt+=preview.
The C filetype plugin distributed with Vim sets the 'omnifunc' option to ccomplete#Complete which supports this option, using the tag signature. I believe it also works for C++. You may need a similar completion function for other languages.
To use it, do "omni" type completion after setting the option, with <C-X><C-O> in insert mode.

Exploring variables of complex types in Eclipse debugging C++

How do I explore the content of a variable of complex type, say, a multimap where key and value are also of some complex type, like some classes.
Debug can only show the value of the pointer, but not the content of the instance of multimap. I know in gdb, if you have a variable var, and it has a method, say, getAddress(), then you can do something like: p var->getAddress() to see the value retured by that function, Can I do something similar in Eclipse Debug?
Hope this helps:
Here is a way to use standard gdb commands from within Eclipse (a console where you can type them in):
Use gdb console in Eclipse
Here are the scripts Joachim mentioned (multimap is supported): http://sourceware.org/gdb/wiki/STLSupport