summaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorSebastien Douheret <sebastien.douheret@iot.bzh>2017-07-13 22:02:20 +0200
committerJosé Bollo <jose.bollo@iot.bzh>2017-07-24 09:34:03 +0200
commitd06b3d9f5bae5424bcada675eaece47b56eb9e3d (patch)
tree93247930e8516d0e1f8cdec3d0c3ea6bd4d84ea2 /scripts
parent5ac881fc974222d7416507ad36e13e1a811fe22e (diff)
Add service debugging support (afm-debug).dab_4.0.0dab/4.0.04.0.0
Add necessary tools/scripts, such as afm-debug, to allow service binding. These tools are only available in develvopment (AGL_DEVEL is set). Change-Id: I4e946146af985c74c8bd97d8c118b932394bbc5e Signed-off-by: Sebastien Douheret <sebastien.douheret@iot.bzh> Signed-off-by: José Bollo <jose.bollo@iot.bzh>
Diffstat (limited to 'scripts')
-rw-r--r--scripts/CMakeLists.txt3
-rw-r--r--scripts/afm-debug90
2 files changed, 93 insertions, 0 deletions
diff --git a/scripts/CMakeLists.txt b/scripts/CMakeLists.txt
index aef41cb..bf0846c 100644
--- a/scripts/CMakeLists.txt
+++ b/scripts/CMakeLists.txt
@@ -20,5 +20,8 @@ cmake_minimum_required(VERSION 2.8)
if(NOT USE_SDK)
install(PROGRAMS afm-util DESTINATION ${CMAKE_INSTALL_BINDIR})
+ if(AGL_DEVEL)
+ install(PROGRAMS afm-debug DESTINATION ${CMAKE_INSTALL_BINDIR})
+ endif()
endif()
diff --git a/scripts/afm-debug b/scripts/afm-debug
new file mode 100644
index 0000000..18ecae2
--- /dev/null
+++ b/scripts/afm-debug
@@ -0,0 +1,90 @@
+#!/bin/bash
+
+###########################################################################
+# Copyright 2017 IoT.bzh
+#
+# Author: Stephane Desneux <sdx@iot.bzh>
+# Sebastien Douheret <sebastien@iot.bzh>
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+###########################################################################
+
+# This script should be invoked by gdb client through a ssh connection.
+# It relays gdbmi protocol from gdbserver to gdb client
+#
+# WARNING: nothing should be sent to stdout except gdbserver output
+
+# FIXME: add support of --debugger option to support tcf or gdb-remote
+
+
+function error() {
+ echo "ERR: $@" >&2
+ exit 1
+}
+function info() {
+ echo "INF: $@" >&2
+}
+
+# setup debug dir (shared with service file)
+DBGDIR=/var/run/afm-debug
+mkdir -p $DBGDIR
+
+# check application name passed as first arg by gdb
+APP=$1
+[[ -z "$APP" ]] && error "Invalid application name"
+
+# redirect to log file
+exec 2>$DBGDIR/$APP.dbgclt.log
+
+# activate DEBUG in environment file sourced in systemd service
+AFB_WAIT_POINT="start-start"
+echo "AFB_DEBUG_WAIT=$AFB_WAIT_POINT" >$DBGDIR/$APP.env
+
+# remove debug env file on exit
+trap "rm $DBGDIR/$APP.*" STOP INT QUIT EXIT
+
+# ask appfw to start application
+pid=$(afm-util start $APP)
+[[ -z "$pid" || ! -e "/proc/$pid" ]] && error "Failed to start application $APP"
+info "$APP started with pid=$pid"
+
+# wait debugging process is stop/waiting at start-start point
+AFB_FILE=/tmp/afb-debug-$pid
+tmo=100
+info "Waiting for process stopped..."
+while [[ ! -e "$AFB_FILE" ]]; do
+ sleep 0.1
+ tmo=$(expr $tmo - 1)
+ [[ "$tmo" == "0" ]] && error "Timeout waiting for process $pid stopped"
+done
+
+info "Waiting for process stopped..."
+AFB_WAIT_FILE=/tmp/afb-debug-$pid
+tmo=100
+res=1
+while [[ "$res" != "0" ]]; do
+ sleep 0.1
+ tmo=$(expr $tmo - 1)
+ [[ "$tmo" == "0" ]] && error "Timeout waiting for process $pid stopped"
+ grep $AFB_WAIT_POINT $AFB_WAIT_FILE > /dev/null 2>&1
+ res=$?
+done
+
+# debugging
+info "Attaching gdbserver to pid $pid ..."
+gdbserver --attach - $pid
+
+# end of debug session
+info "proxy connection terminated - killing $APP (pid $pid)"
+afm-util kill $pid >&2
+info "$APP killed"