Debugging Gbs Submodules

From Tizen Wiki
Jump to: navigation, search

Introduction

This document provides information about how to debug GBS submodules, including the following:

  • Python debugging tool.
  • How to debug gbs submodules?

Python Debugging Tool

This section provides information about python debugging tool.

Installing Python Debugging Tool

The python module pdb defines an interactive source code debugger for Python programs. It supports setting (conditional) breakpoints and single stepping at the source line level, inspection of stack frames, source code listing, and evaluation of arbitrary Python code in the context of any stack frame. It also supports post-mortem debugging and can be called under program control.

An example to install python-ipdb package in debian-based system is shown below:

  $ sudo apt-get install python-ipdb

Debugging Commands

Usual debugging commands:

+--------------+------------------------------------------------+
|Command       |Interpretation                                  |
+==============+================================================+
|b/break       |Set a break there in the current file.          |
+--------------+------------------------------------------------+
|c/continue    |Continue execution, only stop when a breakpoint |
|              |is encountered.                                 |
+--------------+------------------------------------------------+
|l/list        |List source code for the current file.          |
+--------------+------------------------------------------------+
|s/step        |Execute the current line, stop at the first     |
|              |possible occasion (either in a function that is |
|              |called or on the next line inthe current        |
|              |function).                                      |
+--------------+------------------------------------------------+
|r/return      |Continue execution until the current function   |
|              |returns.                                        |
+--------------+------------------------------------------------+
|q/exit        |Quit from the debugger. The program being       |
|              |executed is aborted.                            |
+--------------+------------------------------------------------+
|n/next        |Continue execution until the next line in the   |
|              |current function is reached or it returns.      |
+--------------+------------------------------------------------+
|p             |Evaluate the expression in the current context  |
|              |and print its value.                            |
+--------------+------------------------------------------------+
|help          |Without argument, print the list of available   |
|              |commands. With a command as argument, print help|
|              |about that command.                             |
+--------------+------------------------------------------------+

Debug GBS Submodules

This section provides information about how to debug the GBS submodules.

The Relationship Of GBS And GBP

GBS (git-build-system) is a developer command line tool that supports Tizen package development. It`s used to generate tarballs based on Git repositories, to do local test buildings, and to submit code to OBS (Tizen`s main build service).

GBP(git-build-package) is build packages from git. It is required by GBS.

Debugging Preparation

The typical usage to break into the debugger from a running program is to insert:

   import pdb; pdb.set_trace()

at the location you want to break into the debugger. You can then step through the code following this statement, and continue running without the debugger using the c command.

To start debugging GBS submodules, perform the following procedure:

1. Find the GBS source code path by executing the command `python -c`.

  An example for GBS package is shown below:
     $ python -c "import gitbuildsys;print gitbuildsys.__file__"
     /usr/local/lib/python2.7/dist-packages/gitbuildsys/__init__.pyc
  An example for gbp package is shown below:
     $ python -c "import gbp;print gbp.__file__"
     /usr/local/lib/python2.7/dist-packages/gbp-0.0-py2.7.egg/gbp/__init__.pyc

2. Access to the source code folder.

     $ cd /GBS-source-code-path/gitbuildsys/

3. Open GBS submodules source code, add debug statement before thefirst line of program execution. GBS export submodule source code is cmd_export.py. GBS devel submodule source code is cmd_devel.py. GBS changelog submodule source code is cmd_changelog.py.

  An example for GBS export submodule is shown below:
     $ sudo vi cmd_exort.py
       def main(args):
          """gbs export entry point."""
          import ipdb; ipdb.set_trace()

Debugging GBS submodules

Download a small package from gerrit to facilitate debugging. The command for GBS export submodule is “gbs export”. The command for GBS devel submodule is “gbs devel {start,export, drop,switch,convert}”. The command for GBS changelog submodule is “gbs changelog”.

An example for debugging GBS export submodule is shown below.

  $ gbs export
  > /GBS-source-code-path/gitbuildsys/cmd_export.py(229)main()
      228     import ipdb;ipdb.set_trace()
  --> 229     if args.commit and args.include_all:
      230         raise Usage("--commit cant be specified together with --include-all")

Select n to the execution of the current statement.

  ipdb> n
  > /GBS-source-code-path/gitbuildsys/cmd_export.py(232)main()
      231
  --> 232     workdir = args.gitdir
      233     try:
  ipdb> n
  > / GBS-source-code-path//gitbuildsys/cmd_export.py(233)main()
      232     workdir = args.gitdir
  --> 233     try:
      234         repo = RpmGitRepository(workdir)

Select s to enter function, select r to exit to the call.

  ipdb> n
  > /GBS-source-code-path/gitbuildsys/cmd_export.py(234)main()
      233     try:
  --> 234         repo = RpmGitRepository(workdir)
      235     except GitRepositoryError, err:
  ipdb> s
  --Call--
  >/GBS-source-code-path /dist-packages/gbp-0.0-py2.7.egg/gbp/rpm/git.py(27)__init__()
       26
  ---> 27     def __init__(self, path):
       28         super(RpmGitRepository, self).__init__(path)
  ipdb> n
  >/GBS-source-code-path /dist-packages/gbp-0.0-py2.7.egg/gbp/rpm/git.py(28)__init__()
       27     def __init__(self, path):
  ---> 28         super(RpmGitRepository, self).__init__(path)
       29         self.pristine_tar = PristineTar(self)
  ipdb> r
  --Return--
  None
  >/GBS-source-code-path /dist-packages/gbp-0.0-py2.7.egg/gbp/rpm/git.py(29)__init__()
       28         super(RpmGitRepository, self).__init__(path)
  ---> 29         self.pristine_tar = PristineTar(self)
       30
  ipdb> r
  > /GBS-source-code-path/gitbuildsys/cmd_export.py(238)main()
      237
  --> 238     utils.read_localconf(repo.path)
      239     utils.git_status_checker(repo, args)

Select c to stop the current debug causes program execution to continue.

  ipdb> c
  warning: the following untracked files would NOT be included:
     packaging/acl-2.2.51-0/
  warning: you can specify `--include-all` option to include these uncommitted and untracked files.
  info: tracking branch: origin/upstream -> upstream
  info: tracking branch: origin/pristine-tar -> pristine-tar
  info: Generating patches from git (upstream/2.2.51..HEAD)
  info: Merge commits found! Diff between b761144..f60be9e written into one monolithic diff
  f60be9e
  pristine-tar: successfully generated /var/tmp/.gbs_export_Fmo749/acl-2.2.51.src.tar.gz
  info: package files have been exported to:
       /home/dailang/tizen/acl/packaging/acl-2.2.51-0

Using pdb, step by step, we can easily track the source code and find the relationship between packages. As above shown, GBS will call the function `RpmGitRepository` which defines in gbp. It means that GBS package requires gbp package.

Reference