1// Copyright 2011 the V8 project authors. All rights reserved.
2// Redistribution and use in source and binary forms, with or without
3// modification, are permitted provided that the following conditions are
4// met:
5//
6//     * Redistributions of source code must retain the above copyright
7//       notice, this list of conditions and the following disclaimer.
8//     * Redistributions in binary form must reproduce the above
9//       copyright notice, this list of conditions and the following
10//       disclaimer in the documentation and/or other materials provided
11//       with the distribution.
12//     * Neither the name of Google Inc. nor the names of its
13//       contributors may be used to endorse or promote products derived
14//       from this software without specific prior written permission.
15//
16// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
28// Flags: --ignition-filter=f --expose-debug-as debug
29
30// This test tests that full code compiled without debug break slots
31// is recompiled with debug break slots when debugging is started.
32
33// Get the Debug object exposed from the debug context global object.
34Debug = debug.Debug
35
36var done = false;
37var step_count = 0;
38var values = [];
39
40// Debug event listener which steps until the global variable done is true.
41function listener(event, exec_state, event_data, data) {
42  if (event == Debug.DebugEvent.Break) {
43    if (!done) exec_state.prepareStep(Debug.StepAction.StepNext);
44    step_count++;
45  }
46};
47
48// Set the global variables state to prpare the stepping test.
49function prepare_step_test() {
50  done = false;
51  step_count = 0;
52}
53
54// Test function to step through, uses widended bytecodes.
55function f() {
56var x = 10000000;
57var y = x + 1;
58var _aa = 0; values[_aa] = _aa;
59var _ab = 1; values[_ab] = _ab;
60var _ac = 2; values[_ac] = _ac;
61var _ad = 3; values[_ad] = _ad;
62var _ae = 4; values[_ae] = _ae;
63var _af = 5; values[_af] = _af;
64var _ag = 6; values[_ag] = _ag;
65var _ah = 7; values[_ah] = _ah;
66var _ai = 8; values[_ai] = _ai;
67var _aj = 9; values[_aj] = _aj;
68var _ak = 10; values[_ak] = _ak;
69var _al = 11; values[_al] = _al;
70var _am = 12; values[_am] = _am;
71var _an = 13; values[_an] = _an;
72var _ao = 14; values[_ao] = _ao;
73var _ap = 15; values[_ap] = _ap;
74var _ba = 16; values[_ba] = _ba;
75var _bb = 17; values[_bb] = _bb;
76var _bc = 18; values[_bc] = _bc;
77var _bd = 19; values[_bd] = _bd;
78var _be = 20; values[_be] = _be;
79var _bf = 21; values[_bf] = _bf;
80var _bg = 22; values[_bg] = _bg;
81var _bh = 23; values[_bh] = _bh;
82var _bi = 24; values[_bi] = _bi;
83var _bj = 25; values[_bj] = _bj;
84var _bk = 26; values[_bk] = _bk;
85var _bl = 27; values[_bl] = _bl;
86var _bm = 28; values[_bm] = _bm;
87var _bn = 29; values[_bn] = _bn;
88var _bo = 30; values[_bo] = _bo;
89var _bp = 31; values[_bp] = _bp;
90var _ca = 32; values[_ca] = _ca;
91var _cb = 33; values[_cb] = _cb;
92var _cc = 34; values[_cc] = _cc;
93var _cd = 35; values[_cd] = _cd;
94var _ce = 36; values[_ce] = _ce;
95var _cf = 37; values[_cf] = _cf;
96var _cg = 38; values[_cg] = _cg;
97var _ch = 39; values[_ch] = _ch;
98var _ci = 40; values[_ci] = _ci;
99var _cj = 41; values[_cj] = _cj;
100var _ck = 42; values[_ck] = _ck;
101var _cl = 43; values[_cl] = _cl;
102var _cm = 44; values[_cm] = _cm;
103var _cn = 45; values[_cn] = _cn;
104var _co = 46; values[_co] = _co;
105var _cp = 47; values[_cp] = _cp;
106var _da = 48; values[_da] = _da;
107var _db = 49; values[_db] = _db;
108var _dc = 50; values[_dc] = _dc;
109var _dd = 51; values[_dd] = _dd;
110var _de = 52; values[_de] = _de;
111var _df = 53; values[_df] = _df;
112var _dg = 54; values[_dg] = _dg;
113var _dh = 55; values[_dh] = _dh;
114var _di = 56; values[_di] = _di;
115var _dj = 57; values[_dj] = _dj;
116var _dk = 58; values[_dk] = _dk;
117var _dl = 59; values[_dl] = _dl;
118var _dm = 60; values[_dm] = _dm;
119var _dn = 61; values[_dn] = _dn;
120var _do = 62; values[_do] = _do;
121var _dp = 63; values[_dp] = _dp;
122var _ea = 64; values[_ea] = _ea;
123var _eb = 65; values[_eb] = _eb;
124var _ec = 66; values[_ec] = _ec;
125var _ed = 67; values[_ed] = _ed;
126var _ee = 68; values[_ee] = _ee;
127var _ef = 69; values[_ef] = _ef;
128var _eg = 70; values[_eg] = _eg;
129var _eh = 71; values[_eh] = _eh;
130var _ei = 72; values[_ei] = _ei;
131var _ej = 73; values[_ej] = _ej;
132var _ek = 74; values[_ek] = _ek;
133var _el = 75; values[_el] = _el;
134var _em = 76; values[_em] = _em;
135var _en = 77; values[_en] = _en;
136var _eo = 78; values[_eo] = _eo;
137var _ep = 79; values[_ep] = _ep;
138var _fa = 80; values[_fa] = _fa;
139var _fb = 81; values[_fb] = _fb;
140var _fc = 82; values[_fc] = _fc;
141var _fd = 83; values[_fd] = _fd;
142var _fe = 84; values[_fe] = _fe;
143var _ff = 85; values[_ff] = _ff;
144var _fg = 86; values[_fg] = _fg;
145var _fh = 87; values[_fh] = _fh;
146var _fi = 88; values[_fi] = _fi;
147var _fj = 89; values[_fj] = _fj;
148var _fk = 90; values[_fk] = _fk;
149var _fl = 91; values[_fl] = _fl;
150var _fm = 92; values[_fm] = _fm;
151var _fn = 93; values[_fn] = _fn;
152var _fo = 94; values[_fo] = _fo;
153var _fp = 95; values[_fp] = _fp;
154var _ga = 96; values[_ga] = _ga;
155var _gb = 97; values[_gb] = _gb;
156var _gc = 98; values[_gc] = _gc;
157var _gd = 99; values[_gd] = _gd;
158var _ge = 100; values[_ge] = _ge;
159var _gf = 101; values[_gf] = _gf;
160var _gg = 102; values[_gg] = _gg;
161var _gh = 103; values[_gh] = _gh;
162var _gi = 104; values[_gi] = _gi;
163var _gj = 105; values[_gj] = _gj;
164var _gk = 106; values[_gk] = _gk;
165var _gl = 107; values[_gl] = _gl;
166var _gm = 108; values[_gm] = _gm;
167var _gn = 109; values[_gn] = _gn;
168var _go = 110; values[_go] = _go;
169var _gp = 111; values[_gp] = _gp;
170var _ha = 112; values[_ha] = _ha;
171var _hb = 113; values[_hb] = _hb;
172var _hc = 114; values[_hc] = _hc;
173var _hd = 115; values[_hd] = _hd;
174var _he = 116; values[_he] = _he;
175var _hf = 117; values[_hf] = _hf;
176var _hg = 118; values[_hg] = _hg;
177var _hh = 119; values[_hh] = _hh;
178var _hi = 120; values[_hi] = _hi;
179var _hj = 121; values[_hj] = _hj;
180var _hk = 122; values[_hk] = _hk;
181var _hl = 123; values[_hl] = _hl;
182var _hm = 124; values[_hm] = _hm;
183var _hn = 125; values[_hn] = _hn;
184var _ho = 126; values[_ho] = _ho;
185var _hp = 127; values[_hp] = _hp;
186var _ia = 128; values[_ia] = _ia;
187var _ib = 129; values[_ib] = _ib;
188var _ic = 130; values[_ic] = _ic;
189var _id = 131; values[_id] = _id;
190var _ie = 132; values[_ie] = _ie;
191var _if = 133; values[_if] = _if;
192var _ig = 134; values[_ig] = _ig;
193var _ih = 135; values[_ih] = _ih;
194var _ii = 136; values[_ii] = _ii;
195var _ij = 137; values[_ij] = _ij;
196var _ik = 138; values[_ik] = _ik;
197var _il = 139; values[_il] = _il;
198var _im = 140; values[_im] = _im;
199var _in = 141; values[_in] = _in;
200var _io = 142; values[_io] = _io;
201var _ip = 143; values[_ip] = _ip;
202var _ja = 144; values[_ja] = _ja;
203var _jb = 145; values[_jb] = _jb;
204var _jc = 146; values[_jc] = _jc;
205var _jd = 147; values[_jd] = _jd;
206var _je = 148; values[_je] = _je;
207var _jf = 149; values[_jf] = _jf;
208var _jg = 150; values[_jg] = _jg;
209var _jh = 151; values[_jh] = _jh;
210var _ji = 152; values[_ji] = _ji;
211var _jj = 153; values[_jj] = _jj;
212var _jk = 154; values[_jk] = _jk;
213var _jl = 155; values[_jl] = _jl;
214var _jm = 156; values[_jm] = _jm;
215var _jn = 157; values[_jn] = _jn;
216var _jo = 158; values[_jo] = _jo;
217var _jp = 159; values[_jp] = _jp;
218var _ka = 160; values[_ka] = _ka;
219var _kb = 161; values[_kb] = _kb;
220var _kc = 162; values[_kc] = _kc;
221var _kd = 163; values[_kd] = _kd;
222var _ke = 164; values[_ke] = _ke;
223var _kf = 165; values[_kf] = _kf;
224var _kg = 166; values[_kg] = _kg;
225var _kh = 167; values[_kh] = _kh;
226var _ki = 168; values[_ki] = _ki;
227var _kj = 169; values[_kj] = _kj;
228var _kk = 170; values[_kk] = _kk;
229var _kl = 171; values[_kl] = _kl;
230var _km = 172; values[_km] = _km;
231var _kn = 173; values[_kn] = _kn;
232var _ko = 174; values[_ko] = _ko;
233var _kp = 175; values[_kp] = _kp;
234var _la = 176; values[_la] = _la;
235var _lb = 177; values[_lb] = _lb;
236var _lc = 178; values[_lc] = _lc;
237var _ld = 179; values[_ld] = _ld;
238var _le = 180; values[_le] = _le;
239var _lf = 181; values[_lf] = _lf;
240var _lg = 182; values[_lg] = _lg;
241var _lh = 183; values[_lh] = _lh;
242var _li = 184; values[_li] = _li;
243var _lj = 185; values[_lj] = _lj;
244var _lk = 186; values[_lk] = _lk;
245var _ll = 187; values[_ll] = _ll;
246var _lm = 188; values[_lm] = _lm;
247var _ln = 189; values[_ln] = _ln;
248var _lo = 190; values[_lo] = _lo;
249var _lp = 191; values[_lp] = _lp;
250var _ma = 192; values[_ma] = _ma;
251var _mb = 193; values[_mb] = _mb;
252var _mc = 194; values[_mc] = _mc;
253var _md = 195; values[_md] = _md;
254var _me = 196; values[_me] = _me;
255var _mf = 197; values[_mf] = _mf;
256var _mg = 198; values[_mg] = _mg;
257var _mh = 199; values[_mh] = _mh;
258var _mi = 200; values[_mi] = _mi;
259var _mj = 201; values[_mj] = _mj;
260var _mk = 202; values[_mk] = _mk;
261var _ml = 203; values[_ml] = _ml;
262var _mm = 204; values[_mm] = _mm;
263var _mn = 205; values[_mn] = _mn;
264var _mo = 206; values[_mo] = _mo;
265var _mp = 207; values[_mp] = _mp;
266var _na = 208; values[_na] = _na;
267var _nb = 209; values[_nb] = _nb;
268var _nc = 210; values[_nc] = _nc;
269var _nd = 211; values[_nd] = _nd;
270var _ne = 212; values[_ne] = _ne;
271var _nf = 213; values[_nf] = _nf;
272var _ng = 214; values[_ng] = _ng;
273var _nh = 215; values[_nh] = _nh;
274var _ni = 216; values[_ni] = _ni;
275var _nj = 217; values[_nj] = _nj;
276var _nk = 218; values[_nk] = _nk;
277var _nl = 219; values[_nl] = _nl;
278var _nm = 220; values[_nm] = _nm;
279var _nn = 221; values[_nn] = _nn;
280var _no = 222; values[_no] = _no;
281var _np = 223; values[_np] = _np;
282var _oa = 224; values[_oa] = _oa;
283var _ob = 225; values[_ob] = _ob;
284var _oc = 226; values[_oc] = _oc;
285var _od = 227; values[_od] = _od;
286var _oe = 228; values[_oe] = _oe;
287var _of = 229; values[_of] = _of;
288var _og = 230; values[_og] = _og;
289var _oh = 231; values[_oh] = _oh;
290var _oi = 232; values[_oi] = _oi;
291var _oj = 233; values[_oj] = _oj;
292var _ok = 234; values[_ok] = _ok;
293var _ol = 235; values[_ol] = _ol;
294var _om = 236; values[_om] = _om;
295var _on = 237; values[_on] = _on;
296var _oo = 238; values[_oo] = _oo;
297var _op = 239; values[_op] = _op;
298var _pa = 240; values[_pa] = _pa;
299var _pb = 241; values[_pb] = _pb;
300var _pc = 242; values[_pc] = _pc;
301var _pd = 243; values[_pd] = _pd;
302var _pe = 244; values[_pe] = _pe;
303var _pf = 245; values[_pf] = _pf;
304var _pg = 246; values[_pg] = _pg;
305var _ph = 247; values[_ph] = _ph;
306var _pi = 248; values[_pi] = _pi;
307var _pj = 249; values[_pj] = _pj;
308var _pk = 250; values[_pk] = _pk;
309var _pl = 251; values[_pl] = _pl;
310var _pm = 252; values[_pm] = _pm;
311var _pn = 253; values[_pn] = _pn;
312var _po = 254; values[_po] = _po;
313var _pp = 255; values[_pp] = _pp;
314var _qa = 256; values[_qa] = _qa;
315var _qb = 257; values[_qb] = _qb;
316var _qc = 258; values[_qc] = _qc;
317var _qd = 259; values[_qd] = _qd;
318var _qe = 260; values[_qe] = _qe;
319var _qf = 261; values[_qf] = _qf;
320var _qg = 262; values[_qg] = _qg;
321var _qh = 263; values[_qh] = _qh;
322var _qi = 264; values[_qi] = _qi;
323var _qj = 265; values[_qj] = _qj;
324var _qk = 266; values[_qk] = _qk;
325var _ql = 267; values[_ql] = _ql;
326var _qm = 268; values[_qm] = _qm;
327var _qn = 269; values[_qn] = _qn;
328var _qo = 270; values[_qo] = _qo;
329var _qp = 271; values[_qp] = _qp;
330var _ra = 272; values[_ra] = _ra;
331var _rb = 273; values[_rb] = _rb;
332var _rc = 274; values[_rc] = _rc;
333var _rd = 275; values[_rd] = _rd;
334var _re = 276; values[_re] = _re;
335var _rf = 277; values[_rf] = _rf;
336var _rg = 278; values[_rg] = _rg;
337var _rh = 279; values[_rh] = _rh;
338var _ri = 280; values[_ri] = _ri;
339var _rj = 281; values[_rj] = _rj;
340var _rk = 282; values[_rk] = _rk;
341var _rl = 283; values[_rl] = _rl;
342var _rm = 284; values[_rm] = _rm;
343var _rn = 285; values[_rn] = _rn;
344var _ro = 286; values[_ro] = _ro;
345var _rp = 287; values[_rp] = _rp;
346  done = true;
347};
348
349function check_values() {
350  for (var i = 0; i < values.length; i++) {
351    assertEquals(values[i], i);
352    values[i] = -i;
353  }
354}
355
356// Pass 1 - no debugger, no steps seen
357prepare_step_test();
358f();
359check_values();
360assertEquals(0, step_count);
361
362// Pass 2 - debugger attached and stepping from BP
363Debug.setListener(listener);
364var bp = Debug.setBreakPoint(f, 1);
365prepare_step_test();
366f();
367check_values();
368assertEquals(580, step_count);
369Debug.clearBreakPoint(bp);
370
371// Pass 3 - debugger attached and no BP
372prepare_step_test();
373f();
374check_values();
375assertEquals(0, step_count);
376