【SystemC】libtool + gdbの使い方

SystemC-2.3で、libtoolを使ってコンパイル&リンカした場合の
実行形式ファイルらしきものを見るとスクリプトになっています

SystemC-2.3では多分 libtoolを使うことが推奨されています。

サンプルコード(sc_main.cpp)

#include <systemc.h>

int sc_main(int argc, char *argv[]) {
    printf("Hello World!!!\n");
    sc_start(10, sc_core::SC_NS);

    return 0;
}

コンパイル&ビルド

こちらの Makefile で行いました。
実行履歴は省略します。$> make すると main が生成されます。

mainの中身

#! /bin/bash

# main - temporary wrapper script for .libs/main
# Generated by libtool (GNU libtool) 2.4.2 Debian-2.4.2-1ubuntu1
#
# The main program cannot be directly executed until all the libtool
# libraries that it depends on are installed.
#
# This wrapper script should never be moved out of the build directory.
# If it is, it will not operate correctly.

# Sed substitution that helps us do robust quoting.  It backslashifies
# metacharacters that are still active within double-quoted strings.
sed_quote_subst='s/\([`"$\\]\)/\\\1/g'

# Be Bourne compatible
if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then
  emulate sh
  NULLCMD=:
  # Zsh 3.x and 4.x performs word splitting on ${1+"$@"}, which
  # is contrary to our usage.  Disable this feature.
  alias -g '${1+"$@"}'='"$@"'
  setopt NO_GLOB_SUBST
else
  case `(set -o) 2>/dev/null` in *posix*) set -o posix;; esac
fi
BIN_SH=xpg4; export BIN_SH # for Tru64
DUALCASE=1; export DUALCASE # for MKS sh

# The HP-UX ksh and POSIX shell print the target directory to stdout
# if CDPATH is set.
(unset CDPATH) >/dev/null 2>&1 && unset CDPATH
:
:

ということで、スクリプトになってます。

gdbを使う

純粋にやってしまうと、

$> gdb main
GNU gdb (Ubuntu/Linaro 7.4-2012.04-0ubuntu2.1) 7.4-2012.04
Copyright (C) 2012 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later http://gnu.org/licenses/gpl.html
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "i686-linux-gnu".
For bug reporting instructions, please see:
http://bugs.launchpad.net/gdb-linaro/...
"/hoge/main": not in executable format: ファイル形式が認識できません

というようなエラーがでます。
スクリプトなので、当然なのですが。。。(汗

libtoolを使う場合にはこのように行います。

$> libtool --mode=execute gdb main


$> libtool --mode=execute gdb main
GNU gdb (Ubuntu/Linaro 7.4-2012.04-0ubuntu2.1) 7.4-2012.04
Copyright (C) 2012 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later http://gnu.org/licenses/gpl.html
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "i686-linux-gnu".
For bug reporting instructions, please see:
http://bugs.launchpad.net/gdb-linaro/...
Reading symbols from /hoge/.libs/lt-main...done.
(gdb)

gdb接続が出来ました!!!