-
Notifications
You must be signed in to change notification settings - Fork 1
/
dsource.sh
executable file
·140 lines (111 loc) · 2.29 KB
/
dsource.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#!/bin/bash
function showHelp() {
echo "SYNOPSIS"
echo "\t ./dsource [-ldc] /path/to/{*.a|xx.framework/xx} [/path/to/source]"
echo "DESCRIPTION"
echo "\t -l\tlink a binary path to source code path"
echo "\t -f\t using dwarfdump to find a binary file's compile dir"
echo "\t -c\t check linked files exist at the right path"
}
function check() {
condition=$(basename "$2")
file=($( dwarfdump "$1" | grep -E "DW_AT_decl_file.*$condition.*\.m|\.c" | head -1 | cut -d \" -f2 ))
if [ ! -f $file ]
then
echo "$file" "not exist."
echo "please make sure source path is correct."
exit 0
fi
echo "link successfully!"
echo "view linked source at path:" $2
}
function link() {
dir=($( dwarfdump "$1" | grep "AT_comp_dir" | head -1 | cut -d \" -f2 ))
if [ ! -d $dir ]
then
echo "$dir"
echo "directory does not exist, create one? [y/n]"
read input
if [ $input == 'y' ]
then
sudo mkdir -p $dir
else
exit 0
fi
fi
if [ ! -d $2 ]
then
echo "source directory is not exist, please input the right path."
echo "or manually copy source directory to the path above."
exit 0
fi
EXTENSION="${1##*.}"
if [ $EXTENSION == "a" ]
then
sudo rm $dir
sudo ln -s "$2" $dir
else
BASENAME=$(basename "$1")
NAME=${BASENAME%.*}
sudo ln -s "$2" $dir"/""$NAME"
fi
check $1 $dir
}
function findCompileDir() {
dir=($( dwarfdump "$1" | grep "AT_comp_dir" | head -1 | cut -d \" -f2 ))
if [ ! -d $dir ]
then
echo "directory not exist."
exit 0
fi
echo "compile dir is:" $dir
echo "you may copy source code to this directory, and use dsourc -c to check it"
}
# A POSIX variable
OPTIND=1 # Reset in case getopts has been used previously in the shell.
link=0
check=0
find=0
while getopts "h?clf" opt; do
case "$opt" in
c) check=1
;;
l) link=1
;;
f) find=1
;;
h|\?)
showHelp
exit 0
;;
esac
done
shift $((OPTIND-1))
[ "${1-}" = "--" ] && shift
if [ $link == 1 ]
then
if [ -z "$1" ] || [ -z "$2" ]
then
echo "error: please input pod path and source path"
exit 0
fi
link $1 $2
fi
if [ $find == 1 ]
then
if [ -z "$1" ]
then
echo "error: please input pod path"
exit 0
fi
findCompileDir $1
fi
if [ $check == 1 ]
then
if [ -z "$1" ]
then
echo "error: please input pod path"
exit 0
fi
check $1
fi