xref: /openbmc/openbmc-tools/witherspoon-debug/debug (revision e310dd91688c0b6d6eaee9e6889bf61ee6ce09b7)
1*cf3c1e67SAndrew Jeffery#!/bin/bash
2*cf3c1e67SAndrew Jeffery#
3*cf3c1e67SAndrew Jeffery# SPDX-License-Identifier: Apache-2.0
4*cf3c1e67SAndrew Jeffery# Copyright (C) 2018 IBM Corp.
5*cf3c1e67SAndrew Jeffery
6*cf3c1e67SAndrew Jefferyset -eou pipefail
7*cf3c1e67SAndrew Jeffery
8*cf3c1e67SAndrew Jefferyif [ $# -lt 2 ]
9*cf3c1e67SAndrew Jefferythen
10*cf3c1e67SAndrew Jeffery    echo Usage: $0 [user@][host] [tarball]
11*cf3c1e67SAndrew Jeffery    exit 1
12*cf3c1e67SAndrew Jefferyfi
13*cf3c1e67SAndrew Jeffery
14*cf3c1e67SAndrew JefferyTARGET="$1"
15*cf3c1e67SAndrew JefferyDEBUGTOOLS_PATH="$2"
16*cf3c1e67SAndrew JefferyDEBUGTOOLS="$(basename "${DEBUGTOOLS_PATH}")"
17*cf3c1e67SAndrew Jeffery
18*cf3c1e67SAndrew Jefferyscp "${DEBUGTOOLS_PATH}" libncurses.so.5.9 libncursesw.so.5.9 "${TARGET}":/tmp/
19*cf3c1e67SAndrew Jefferyssh "${TARGET}" <<-EOF
20*cf3c1e67SAndrew Jefferyset -eou pipefail
21*cf3c1e67SAndrew Jeffery
22*cf3c1e67SAndrew Jefferyset -x
23*cf3c1e67SAndrew Jeffery
24*cf3c1e67SAndrew Jefferyon_exit() {
25*cf3c1e67SAndrew Jeffery	rm -f /tmp/'${DEBUGTOOLS}'
26*cf3c1e67SAndrew Jeffery	rm -f /tmp/libncurses.so.5.9 /tmp/libncursesw.so.5.9
27*cf3c1e67SAndrew Jeffery}
28*cf3c1e67SAndrew Jeffery
29*cf3c1e67SAndrew Jefferytrap on_exit EXIT
30*cf3c1e67SAndrew Jeffery
31*cf3c1e67SAndrew Jeffery# Deal with field mode
32*cf3c1e67SAndrew Jefferyif ! mountpoint /usr/local
33*cf3c1e67SAndrew Jefferythen
34*cf3c1e67SAndrew Jeffery	systemctl unmask usr-local.mount
35*cf3c1e67SAndrew Jeffery	systemctl start usr-local.mount
36*cf3c1e67SAndrew Jefferyfi
37*cf3c1e67SAndrew Jeffery
38*cf3c1e67SAndrew Jeffery# Untar debug tools tarball into /usr/local
39*cf3c1e67SAndrew Jefferypushd /usr/local
40*cf3c1e67SAndrew Jefferytar -xvJf /tmp/"${DEBUGTOOLS}"
41*cf3c1e67SAndrew Jefferypopd
42*cf3c1e67SAndrew Jeffery
43*cf3c1e67SAndrew Jeffery# Work around bugs preventing perf from working
44*cf3c1e67SAndrew Jeffery# Tracking issue: https://github.com/openbmc/openbmc/issues/2880
45*cf3c1e67SAndrew Jeffery
46*cf3c1e67SAndrew Jeffery# Fake expand(1): https://github.com/openbmc/openbmc/issues/2879
47*cf3c1e67SAndrew Jefferymkdir -p bin
48*cf3c1e67SAndrew Jefferypushd /usr/local/bin
49*cf3c1e67SAndrew Jeffery# which expand isn't enough as expand might be a symlink to a busybox not built with CONFIG_EXPAND
50*cf3c1e67SAndrew Jefferyif ! echo "" | expand
51*cf3c1e67SAndrew Jefferythen
52*cf3c1e67SAndrew Jeffery	# Remove what is likely a symlink to busybox before trying to overwrite
53*cf3c1e67SAndrew Jeffery	# file because:
54*cf3c1e67SAndrew Jeffery	#
55*cf3c1e67SAndrew Jeffery	# 1) We get errors through trying to write to a read-only filesystem
56*cf3c1e67SAndrew Jeffery	# 2) If the filesystem were read-write, we would overwrite the busybox binary
57*cf3c1e67SAndrew Jeffery	[ -f expand ] && rm expand
58*cf3c1e67SAndrew Jeffery	# Fake out expand(1) in the cheapest way possible
59*cf3c1e67SAndrew Jeffery	echo -e "#!/bin/sh\ncat" > expand
60*cf3c1e67SAndrew Jeffery	chmod +x expand
61*cf3c1e67SAndrew Jefferyfi
62*cf3c1e67SAndrew Jeffery
63*cf3c1e67SAndrew Jeffery# Fix the broken objdump link: https://github.com/openbmc/openbmc/issues/2878
64*cf3c1e67SAndrew Jefferyln -sf arm-openbmc-linux-gnueabi-objdump objdump
65*cf3c1e67SAndrew Jefferypopd
66*cf3c1e67SAndrew Jeffery
67*cf3c1e67SAndrew Jeffery# perf-config(1) is terrible and won't write your configuration unless the
68*cf3c1e67SAndrew Jeffery# configuration file exists
69*cf3c1e67SAndrew Jefferytouch \${HOME}/.perfconfig
70*cf3c1e67SAndrew Jeffery
71*cf3c1e67SAndrew Jeffery# Disable writing junk to \${HOME}, otherwise we fill up the RW volume and
72*cf3c1e67SAndrew Jeffery# cause systemic failures.
73*cf3c1e67SAndrew JefferyLD_LIBRARY_PATH=/usr/local/lib /usr/local/bin/perf config --user buildid.dir=/dev/null
74*cf3c1e67SAndrew Jeffery
75*cf3c1e67SAndrew Jeffery# Deal with latencytop's missing shared object dependency on ncurses, tracked by
76*cf3c1e67SAndrew Jeffery# https://github.com/openbmc/openbmc/issues/2430
77*cf3c1e67SAndrew Jefferypushd /usr/local/lib
78*cf3c1e67SAndrew Jefferyif [ -f /tmp/libncurses.so.5.9 -o -f /tmp/libncursesw.so.5.9 ]
79*cf3c1e67SAndrew Jefferythen
80*cf3c1e67SAndrew Jeffery	cp /tmp/libncurses.so.5.9 /tmp/libncursesw.so.5.9 .
81*cf3c1e67SAndrew Jeffery	ln -sf libncurses.so.5.9 libncurses.so.5
82*cf3c1e67SAndrew Jeffery	ln -sf libncurses.so.5.9 libncurses.so
83*cf3c1e67SAndrew Jeffery	ln -sf libncursesw.so.5.9 libncursesw.so.5
84*cf3c1e67SAndrew Jeffery	ln -sf libncursesw.so.5.9 libncursesw.so
85*cf3c1e67SAndrew Jefferyfi
86*cf3c1e67SAndrew Jefferypopd
87*cf3c1e67SAndrew JefferyEOF
88*cf3c1e67SAndrew Jeffery
89*cf3c1e67SAndrew Jefferyecho
90*cf3c1e67SAndrew Jefferyecho Make sure to run the following in your shell:
91*cf3c1e67SAndrew Jefferyecho
92*cf3c1e67SAndrew Jefferyecho export LD_LIBRARY_PATH=/usr/local/lib PYTHONPATH=/usr/local/lib/python2.7
93*cf3c1e67SAndrew Jefferyecho
94