Sys.Signals module for a Variant type of signals (and a set_signal function that...
[ocaml.git] / debugger / pos.ml
blob4beba3de0fcf2540b15f94285b339dc8415c5f6d
1 (***********************************************************************)
2 (* *)
3 (* Objective Caml *)
4 (* *)
5 (* Damien Doligez, projet Moscova, INRIA Rocquencourt *)
6 (* *)
7 (* Copyright 2003 Institut National de Recherche en Informatique et *)
8 (* en Automatique. All rights reserved. This file is distributed *)
9 (* under the terms of the Q Public License version 1.0. *)
10 (* *)
11 (***********************************************************************)
13 (* $Id$ *)
15 open Instruct;;
16 open Lexing;;
17 open Location;;
18 open Primitives;;
19 open Source;;
21 let get_desc ev =
22 let loc = ev.ev_loc in
23 if loc.loc_start.pos_fname <> ""
24 then Printf.sprintf "file %s, line %d, characters %d-%d"
25 loc.loc_start.pos_fname loc.loc_start.pos_lnum
26 (loc.loc_start.pos_cnum - loc.loc_start.pos_bol + 1)
27 (loc.loc_end.pos_cnum - loc.loc_start.pos_bol + 1)
28 else begin
29 let filename = source_of_module ev.ev_loc.loc_start ev.ev_module in
30 try
31 let (start, line) = line_of_pos (get_buffer loc.loc_start ev.ev_module)
32 loc.loc_start.pos_cnum
34 Printf.sprintf "file %s, line %d, characters %d-%d"
35 filename line (loc.loc_start.pos_cnum - start + 1)
36 (loc.loc_end.pos_cnum - start + 1)
37 with Not_found | Out_of_range ->
38 Printf.sprintf "file %s, characters %d-%d"
39 filename (loc.loc_start.pos_cnum + 1)
40 (loc.loc_end.pos_cnum + 1)
41 end