Dev Notes

Emacs

Org mode

Org2Blog

Capture

C-c c Capture , then select capture ation.

Easy templates or how to insert code snippets ez

Links

C-c C-o open link

Links to email with mu4e

This is really cool

Add to init.el :

(require 'org-mu4e)

Then use C-c l (org-store-link) in an email view in mu4e

And C-c C-l (org-insert-link) to insert it in your org file

mu4e

Example search query

maildir:/INBOX NOT NOT to:gdb-patches@sourceware.org NOT cc:gdb-patches@sourceware.org NOT to:gdb@sourceware.org NOT cc:gdb

Note to enable the search query you must actually restart emacs.

Keybinding

Headers view:

W : Show related, useful as it shows the full threads related to my bt mails

Gnus

Tutorial

Setup is in ~/.gnus.el (maybe better somewhere else) M-x gnus to start A A to list all groups u to subscribe RET on group to enter

I found this to be way too complicated to use after all, at least for now I’m more confortable with mu4e.

elisp

Open manual M-x info-display-manual eslip

Exercices

Tags

Refresh tags helm-gtags-create-tags

C/C++ Ide

Refactoring semantic-refactor

Use M-RET in c/cpp mode

can move functions, rename local vars, generate prototype see: https://github.com/tuhdo/semantic-refactor

PDFs

How to Read PDFs using emacs:

Use the excellent pdf-tools : https://github.com/politza/pdf-tools

  • Useful keys :

    o : Prints the outline in a buffer

Taking notes in a pdf

Other

Making a new frame : make-frame-command

Problems with gpg2 on arch

Kill gpg-agent and restart emacs it should ask for the password inside emacs diretly if not see pinentry …

Clojure

How to have faster startup time

This is quite usefull for scripts.

See : Drip

How to specify the JAVA command

Quick start

install drip and add

faster clojure
export LEIN_JAVA_CMD=drip
to zshrc

then a script with

#!/usr/bin/env lein-exec

is fast!! 🙂

Emacs

Other

GDB

Extensions

Python exploit assistant

Racy tests

To identify racy tests in GDB you can use this tool like so :

make check RACY_ITER=3 -j2

See: https://sourceware.org/ml/gdb-patches/2016-02/msg00490.html

Testing arm fast tracepoints on a target board from a x86 host

With this you can have a x86 host that will run fast tracepoints tests on an arm board for example.

First make a board file like so:

# gdbserver running remotely over ssh

load_generic_config "gdbserver"

process_multilib_options ""

# The default compiler for this target.
#set_board_info compiler  "[find_gcc]"
# If gdbserver runs in a cross-target arch, the testsuite should use a cross-compiler
set_board_info compiler  "arm-linux-gnueabihf-gcc"
set_board_info c++compiler  "arm-linux-gnueabihf-g++"

set_board_info rsh_prog "/usr/bin/ssh"
set_board_info rcp_prog "/usr/bin/scp"
set_board_info protocol standard
set_board_info username MYUSERNAME
set_board_info hostname MYBOARDIP

# Path to the gdbserver executable on target board.
set_board_info gdb_server_prog MYARMGDBSERVERPATH
# We will be using the standard GDB remote protocol
set_board_info gdb_protocol "remote"

# Name of the computer whose socket will be used, if required.
set_board_info sockethost MYBOARDIP

# Port ID to use for socket connection
#set_board_info gdb,socketport "4004"

# Use techniques appropriate to a stub
set_board_info use_gdb_stub 1

# This gdbserver can only run a process once per session.
set_board_info gdb,do_reload_on_run 1

# There's no support for argument-passing (yet).
set_board_info noargs 1

# Can't do input (or output) in the current gdbserver.
set_board_info gdb,noinferiorio 1

# Can't do hardware watchpoints, in general (it depends on gdbserver support for your target arch)
set_board_info gdb,no_hardware_watchpoints 1

Put it in binutils-gdb/gdb/testsuite/boards/

Replace all MY* with your prefered values.

Now to run the tests you will need to compile a GDB for x86 and a GDBServer for arm.

Create 2 build directories:

build-x86-arm-cross : Contains the x86 build with an arm target

build-arm: Contains the arm GDBServer build.

Configure them:

build-x86-arm-cross:

../configure --disable-binutils --disable-ld --disable-gold --disable-gas --disable-sim --disable-gprof --target=arm-linux-gnueabihf

build-arm: Contains the arm GDBServer build.

../configure --with-expat
--with-libexpat-prefix=/usr/local/expat/arm/2.1.0 --target
arm-linux-gnueabihf  --host arm-linux-gnueabihf --disable-binuils
--disable-ld --disable-gold --disable-gas --disable-sim --disable-gprof

You need am arm expat built library on your system for this one.

Then create a symlink to the arm built gdbserver in build-x86-arm-cross

cd  build-x86-arm-cross/gdb
ln -s ../../build-arm/gdb/gdbserver

Then run this command to build, scp your arm gdbserver to be tested to the target and run the tests.

make -j6 -C build-arm && make -j6 -C build-x86-arm-cross && scp build-arm/gdb/gdbserver/gdbserver MYUSER@MYBOARDIP: && cd build-x86-arm-cross/gdb && make check RUNTESTFLAGS="--target_board=remote-board ftrace.exp"

Building in 32bits (i386)

apt-get install g++-4.8-multilib linux-libc-dev:i386
AR=ar CFLAGS="-O0 -g3 -m32" CXXFLAGS="-O0 -g3 -m32" ../configure --disable-binutils --disable-ld --disable-gold --disable-gas --disable-sim --disable-gprof --enable-targets=all --host=i386-linux-gnu

Make it easy to debug gdb or gdbserver using terminator sessions and zsh aliases

This is for zsh

alias gdb="~/src/binutils-gdb/build-x86/gdb/gdb -D ~/src/binutils-gdb/build-x86/gdb/data-directory"
alias gdbserver="~/src/binutils-gdb/build-x86/gdb/gdbserver/gdbserver"
#This starts a terminator session with a vertical split one with gdb the other with gdbserver
alias debug-gdb="terminator -l gdb-debug"

To debug gdbserver gdb gdbserver_path.

Terminator layout:

[[gdb-debug]]
  [[[child0]]]
    position = 2216:210
    type = Window
    order = 0
    parent = ""
    size = 1130, 902
  [[[child1]]]
    position = 434
    type = VPaned
    order = 0
    parent = child0
  [[[terminal3]]]
    profile = debug-gdb
    command = ~/src/binutils-gdb/build-x86/gdb/gdb -D ~/src/binutils-gdb/build-x86/gdb/data-directory -ex "tar rem :7777" ; zsh
    type = Terminal
    order = 1
    parent = child1
  [[[terminal2]]]
    profile = debug-gdb
    command = ~/src/binutils-gdb/build-x86/gdb/gdbserver/gdbserver :7777 ~/src/binutils-gdb/build-x86/gdb/gdb ; zsh
    type = Terminal
    order = 0
    parent = child1

Updated the wiki this this…

Set the disassembly mode arm/thumb

set arm force-mode (arm|thumb|auto) This command overrides use of the symbol table to determine whether instructions are ARM or Thumb. The default is ‘auto’, which causes gdb to use the symbol table and then the setting of ‘set arm fallback-mode’.

set arm fallback-mode (arm|thumb|auto) gdb uses the symbol table, when available, to determine whether instructions are ARM or Thumb. This command controls gdb’s default behavior when the symbol table is not available. The default is ‘auto’, which causes gdb to use the current execution mode (from the T bit in the CPSR register).

Links

Ideas

Add a file output to gdbserver –debug so that we can use debug output with the test suite

Lsyncd

Removing source files after sync:

See this issue: https://github.com/axkibe/lsyncd/issues/258

Use –remove-source-files

Learning

Coursera

Ulondon malware IDA/gdb debug

Heterogenous computing CUDA (seems better then the udacity one)

Workflow

Checking patch for syntax issues

I use clangformat to check my patches for syntax issues see: http://clang.llvm.org/docs/ClangFormat.html

apt-get install clang-format

Download this file clang-format.txt Move the file to your binutils-gdb/ direcotry as .clang-format

Then to check a patch and make a diff of the changes clang suggests:

git diff -U0 HEAD^ | clang-format-diff-3.6 -style=file -p1  > clang-format-diffed

Starting up gdb from Emacs with the right pid automatically

Let’s say I’m debugging gdb using a test. I always ended up looking for the pid of the gdb under test with ps then copy & pasting it to the gdb start command.

But there’s now a better way with this little bit of elisp:

(defun gdb-test ()
  "Run gdb with the pid of the gdb currectly executing a test"
  (interactive)
  (gdb (concat gud-gdb-command-name (format " -p %s" (system-process-pid "gdb.*-nw.*-nx")))))

(defun system-process-pid (regex-str)
  "Return the pid for a process with args matching regex-str"
  (dolist (pid (list-system-processes))
    (let ((attrs (process-attributes pid)))
      (if (string-match-p regex-str
			  (cdr (assoc 'args attrs)))
	  (return pid)))))

(provide 'custom-lib)

This will find the pid of the gdb under test, assuming that it always has -nw.*-nw it it’s arguments.

So calling M-x gdb-test will start gdb with the pid of the gdb under test et voila 🙂

Events

Hope XI July 2016

Talks

This is a list of talks I’m interested in:

Leave a Reply

Your email address will not be published. Required fields are marked *