Miscellaneous Notes
This page is a dumping ground for all kinds of notes that may eventually morph into full articles or reference pages with improved organization.
Network MTUs
Network Type | MTU |
---|---|
16 Mbps Token Ring | 17914 |
4 Mbps Token Ring | 4464 |
FDDI | 4352 |
Ethernet | 1500 |
IEEE 802.3/802.2 | 1492 |
PPPoE (WAN Miniport) | 1480 |
X.25 | 576 |
Keyboard Key Mapping Collisions
The following table shows keys that are mapped in such a way that they are indistinguishable from each other. This is true at least in Emacs on *nix (including graphical Emacs under X), but may be true throughout Unix. Note to self: Research further and update these notes when possible.
Key | Equivalent |
---|---|
C-m | RET |
C-i | TAB |
C-[ | ESC |
Profiling with GCC and gprof
A software profiler is a very useful tool for determining where your program code is spending most of its processor cycles.
GCC provides this functionality in the form of software instrumentation that it can build into your program.
To see it in action, compile and link with GCC's -pg option. It is important to provide this option to both compiler and linker.
For example, if the program source is in main.c:
$ gcc -Wall -c -pg main.c $ gcc -Wall -pg main.o
Now run the executable normally:
$ ./a.out
Data is collected into gmon.out in the current directory. Note that gmon.out is in a binary format and as such won't make much sense if you attempt to view it directly. To see the contents in a sensible way, run gprof with the name of the executable (not gmon.out) as an argument:
$ gprof a.out | less
List Shared Objects Used By A Program
Sometimes you need to know which shared objects (dynamically linked libraries) a program uses. I've run into this need multiple times on different operating systems.
On Linux and most Unix systems, if you have an installed GCC toolchain:
$ objdump -p /path/to/executable | grep NEEDED
If the executable is for a different target architecture, use the objdump provided with the cross-compiler toolchain for that architecture. For example:
$ arm-none-eabi-objdump -p /path/to/executable | grep NEEDED
Note that the above commands will show only the direct library dependencies of the executable. Those dependencies may have additional dependencies of their own, which will not be shown because objdump will not recursively analyze them. (A script could be written to do so and either display the results hierarchically or simply sort and uniq the list to avoid showing the same dependency twice.)
If you trust the executable you are checking, another option is ldd, which does show complete dependency information. As I understand it, different implementations might use different methods to obtain this information, one of which is to set a special environment variable, LD_TRACE_LOADED_OBJECTS, and execute the program. The dynamic linker is supposed to recognize this environment variable and print the dependency information instead of actually executing the program itself, but this depends entirely on the executable in question! The executable could be made to run any arbitrary code. Therefore, only use ldd with trusted executables! This is explained in detail in the Linux man page for ldd. The OpenBSD man page for ldd is, let's say, much more succinct than the Linux one: "ldd displays the shared objects needed to run program. ldd uses the DT_NEEDED tags to determine what dynamic objects are required. To list the objects ldd sets the environment variable LD_TRACE_LOADED_OBJECTS and then execs program." (At the time of this writing, that's basically the entire man page!)
$ ldd /path/to/trusted/executable
On macOS (formerly Mac OS X), the installed compiler toolchain is clang and its objdump has different usage semantics than GCC's objdump. I have not yet figured out how to use it to list shared libraries, but there is a program, otool, which invokes objdump with the necessary options:
$ otool -L /path/to/executable
See its man page for details.
Linux Serial Port Command Lines
In these example, the serial port is identified as /dev/ttyAMA0 and the BAUD rate is 115200 bits per second. Replace these with the actual device path and BAUD rate.
To set or check the serial port's BAUD rate:
$ stty -F /dev/ttyAMA0 115200
To send data to the port without newlines (where DATA is the data you want to send):
$ echo -n DATA > /dev/ttyAMA0
Send feedback to: the name of this blog at mail dot com.