summaryrefslogtreecommitdiff
path: root/gdb/testsuite/config/symbian.exp
blob: 17e4388b8186511c839c0d6f60571b0855b92b4d (plain)
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
load_lib gdb.exp

proc epoc_run { outvar args } {
    global env
    global epocpaths

    upvar $outvar output

    set oldpath $env(PATH)
    set env(PATH) "$epocpaths:$env(PATH)"

    set result [catch { eval $args } output]

    set env(PATH) $oldpath

    return $result
}

proc cyg_to_win { source } {
    set result [file native [file normalize $source]]
    if { [string first "C:" $result] != -1 } {
	set result [string map {C: ""} $result]
    } else {
	# This appears to be a Unix-thinking sort of TCL.
	set result "\\cygwin[string map {/ \\} $result]"
    }
    return $result
}

proc symbian_compile { sources destfile type options } {
    global object_map
    global epocroot

    if { $type == "object" } {
	# We can't really do this.  Instead, queue up the objects
	# for later.  Discard the options and hope the right ones
	# are around later.

	set object_map($destfile) $sources
	return ""
    }

    if { $type == "preprocess" } {
	# GDB just uses this for version information, so don't
	# worry about getting the right compiler options.

	# Hack: We're Cygwin, the SymbianOS GNU toolchain is mingw32.
	# Modify sources.
	set mysources ""
	foreach source $sources {
	    lappend mysources [exec cygpath -w "$source"]
	}

	epoc_run output default_target_compile $mysources $destfile $type $options
	return $output
    }

    if { $type != "executable" } {
	return "unsupported compile type: $type"
    }

    set mysources ""
    foreach source $sources {
	if { [info exists object_map($source)] } {
	    lappend mysources $object_map($source)
	    unset object_map($source)
	} else {
	    lappend mysources $source
	}
    }

    # By default use the non-debuggable copy.
    set reldir "urel"

    set allflags ""
    set incdirs {}
    foreach option $options {
	# send_user "option: $option\n"
	if { $option == "debug" } {
	    set reldir "udeb"
	} elseif { $option == "c++" } {
	    # Nothing
	} elseif { [regexp -all {additional_flags=(.*)} $option dummy flags] } {
	    append allflags " $flags"
	} elseif { [regexp -all {incdir=(.*)} $option dummy value] } {
	    lappend incdirs $value
	} else {
	    warning "Compilation option $option not supported"
	    return -1
	}
    }

    set proj [file tail $destfile]

    # Write out a new bld.inf.  Puts sticks a newline at the end
    # of each string; we have extras because we want blank line
    # separators.
    set inffile [open "bld.inf" "w"]
    puts $inffile "PRJ_PLATFORMS\n"
    puts $inffile "BASEDEFAULT GCCE\n"
    puts $inffile "PRJ_EXPORTS\n"
    puts $inffile "PRJ_MMPFILES\n${proj}.mmp"
    close $inffile

    set bldfile [open "${proj}.mmp" "w"]
    puts $bldfile "TARGET ${proj}.exe"
    puts $bldfile "TARGETTYPE EXE"
    puts $bldfile "SOURCEPATH \\."
    foreach source $mysources {
	set result [cyg_to_win $source]
	# send_user "orig source $source, new source $result\n"
	puts $bldfile "SOURCE $result"
    }
    foreach incdir $incdirs {
	puts $bldfile "USERINCLUDE [cyg_to_win $incdir]"
    }
    puts $bldfile "LIBRARY EUSER.LIB"
    puts $bldfile "LIBRARY ESTLIB.LIB"
    puts $bldfile "STATICLIBRARY MYECRT0.LIB"
    puts $bldfile "SYSTEMINCLUDE \\EPOC32\\INCLUDE\\LIBC"
    puts $bldfile "SYSTEMINCLUDE \\EPOC32\\INCLUDE"
    # Request these capabilities to match ESTLIB.LIB; if we ask for
    # ALL, SymbianOS will refuse to launch us.
    puts $bldfile "CAPABILITY All -Tcb"
    puts $bldfile "VENDORID 0x70000001"
    if { $allflags != "" } {
	puts $bldfile "OPTION GCCE $allflags"
    }
    close $bldfile

    epoc_run output exec "bldmake.bat" "bldfiles" "GCCE"
    # send_user "bldmake output: $output END\n"

    epoc_run output exec "./ABLD.BAT" "REALLYCLEAN" "GCCE"
    # send_user "abld clean output: $output END\n"

    if { [file exists "$epocroot/epoc32/release/gcce/${reldir}/${proj}.exe"] } {
	perror "abld reallyclean has failed to remove ${proj}.exe"
    }

    epoc_run output exec "./ABLD.BAT" "BUILD" "GCCE"
    # send_user "abld build output: $output END\n"

    if { ! [file exists "$epocroot/epoc32/release/gcce/${reldir}/${proj}.exe"] } {
	# Build must have failed.  Exit codes appear to be useless
	# for these tools.
	return "$output"
    }

    file copy -force -- "$epocroot/epoc32/release/gcce/${reldir}/${proj}.exe" ${destfile}.exe

    # Don't look for a .sym file in that same directory; UDEB has one but
    # UREL doesn't.  Grab the .exe from the temporary build directory instead.
    # file copy -force -- "$epocroot/epoc32/release/gcce/${reldir}/${proj}.sym" ${destfile}

    set result [file native [file normalize [pwd]]]
    if { [string first "C:" $result] != -1 } {
	set result [string map {C: ""} $result]
    } else {
	# This appears to be a Unix-thinking sort of TCL.
	set result "/cygwin/$result"
    }
    file copy -force -- "$epocroot/epoc32/BUILD$result/${proj}/gcce/${reldir}/${proj}.exe" ${destfile}

    # file delete "bld.inf"
    # file delete "${proj}.mmp"
    epoc_run output exec "./ABLD.BAT" "REALLYCLEAN" "GCCE"
    # send_user "abld clean output: $output END\n"

    return ""
}

proc gdb_target_symbian {} {
    global gdb_prompt
    global timeout

    if { [target_info exists baudrate] } {
	gdb_test "set remotebaud [target_info baudrate]" "" ""
    }

    set prev_timeout $timeout
    set timeout 60
    verbose "Timeout is now $timeout seconds" 2
    gdb_test_multiple "target extended-remote [target_info netport]" "" {
        -re ".*\[Ee\]rror.*$gdb_prompt $" {
            perror "Couldn't set target for remote board."
            cleanup
            gdb_exit
        }
        -re "Remote debugging using.*$gdb_prompt" {
            verbose "Set target to [target_info netport]"
        }
        timeout {
            perror "Couldn't set target for remote board."
            cleanup
            gdb_exit
        }
    }
    set timeout $prev_timeout
    verbose "Timeout is now $timeout seconds" 2

    # TEMPORARY
    # gdb_test "set debug remote 1" "" ""
}

proc infer_host_exec { } {
    global gdb_prompt
    global mi_gdb_prompt

    set host_exec ""

    send_gdb "info files\n"
    gdb_expect 30 {
	-re "Symbols from \"(\[^\"\]+)\"" {
	    set host_exec $expect_out(1,string)
	    exp_continue
	}
	-re "Local exec file:\[\r\n\]+\[ \t\]*`(\[^'\]+)'," {
	    set host_exec $expect_out(1,string)
	    exp_continue
	}
	-re "$gdb_prompt $" { }
	-re "$mi_gdb_prompt$" { }
    }

    return $host_exec
}

set saved_host_exec ""

proc gdb_load { arg } {
    global exec_downloaded
    global saved_host_exec

    set board_exec [target_info exec_file]

    gdb_target_symbian

    gdb_test "kill" "" "" "Kill the program being debugged.*y or n. $" "y"

    set quoted_board_exec [string map {\\ \\\\} $board_exec]
    gdb_test "set remote exec-file \"$quoted_board_exec\"" "" ""

    # If we weren't passed an explicit binary, try to reuse the current
    # one.  If we were, be sure to redownload it.

    if { $arg == "" && $saved_host_exec == "" } {
	set saved_host_exec [infer_host_exec]
    } elseif { $arg != "" } {
        set saved_host_exec $arg
        if [info exists exec_downloaded] { unset exec_downloaded }
	if [gdb_file_cmd $arg] { return -1 }
    }

    if { ! [info exists exec_downloaded] } {
	global timeout
	set prev_timeout $timeout
	set timeout 60
	gdb_test "remote-download ${saved_host_exec}.exe $quoted_board_exec" "" ""
	set timeout $prev_timeout

	set exec_downloaded 1
    }
}

proc mi_target_gdb_load { arg } {
    global exec_downloaded
    global saved_host_exec

    set board_exec [target_info exec_file]

    if { [target_info exists baudrate] } {
	mi_gdb_test "-gdb-set remotebaud [target_info baudrate]" "" ""
    }

    if { [mi_gdb_target_cmd "extended-remote" "[target_info netport]"] != 0 } {
	return -1
    }

    # Kill if something is running, but prevent a failure if nothing is.
    set none_re "&\"The program is not being run.\\\\n\"\[\r\n\]+"
    mi_gdb_test "kill" "&\"kill\\\\n\"\[\r\n\]+($none_re)?\\^done" ""

    set quoted_board_exec [string map {\\ \\\\} $board_exec]
    mi_gdb_test "-gdb-set remote exec-file \"$quoted_board_exec\"" "" ""

    # If we weren't passed an explicit binary, try to reuse the current
    # one.  If we were, be sure to redownload it.

    if { $arg == "" && $saved_host_exec == "" } {
	set saved_host_exec [infer_host_exec]
    } elseif { $arg != "" } {
        set saved_host_exec $arg
        if [info exists exec_downloaded] { unset exec_downloaded }
    }

    if { ! [info exists exec_downloaded] } {
	global timeout
	set prev_timeout $timeout
	set timeout 60
	mi_gdb_test "remote-download ${saved_host_exec}.exe $quoted_board_exec" "" ""
	set timeout $prev_timeout

	set exec_downloaded 1
    }

    return 0
}