Loading ...
Sorry, an error occurred while loading the content.

A question about the usage of ocamldebug

Expand Messages
  • Andy Yang
    Hi, all When I tried to use list command in ocaml debug, I was told Not in a module . Actually I wrote some very simple code, and do not use modules. How
    Message 1 of 9 , Jul 6, 2004
    View Source
    • 0 Attachment
      Hi, all

      When I tried to use "list" command in ocaml debug, I
      was told "Not in a module". Actually I wrote some very
      simple code, and do not use modules. How shall I set
      break points and list the programs?

      Thanks a lot!

      Andy



      __________________________________
      Do you Yahoo!?
      Yahoo! Mail is new and improved - Check it out!
      http://promotions.yahoo.com/new_mail
    • Matt Gushee
      ... Well, saying that Camlp4 is a preprocessor is true, but perhaps also a bit confusing. The input can be just about anything you like, but in most cases, you
      Message 2 of 9 , Jul 6, 2004
      View Source
      • 0 Attachment
        On Tue, Jul 06, 2004 at 05:45:24PM -0700, Andy Yang wrote:

        > So, what is the input for camlp4?

        Well, saying that Camlp4 is a preprocessor is true, but perhaps
        also a bit confusing. The input can be just about anything you
        like, but in most cases, you have to provide appropriate syntax
        definitions.

        > Ocaml, there are not header files like those in C/C++.

        No, there certainly aren't. I guess the easiest way to put it is
        that you can use Camlp4 to process OCaml code with extensions
        (such as ifdefs) or modified syntax (such as the OCaml revised syntax,
        which is supposed to be more logical than the normal syntax, but is not
        very widely used). But you can also use it to implement any language:
        Camlp4 can parse your other language based on a grammar that you have
        defined, and it then feeds an abstract syntax tree to Caml itself.

        The downside is that Camlp4 doesn't do very much out of the box.
        You can use it for conditional compilation ... hmm, haven't done this
        lately, but I believe the command looks like this:

        ocamlc -pp "camlp4o pa_ifdef.cmo" -I camlp4 -c foo.ml

        Or you can process the revised syntax:

        ocamlc -pp camlp4r -c foo.ml

        There may be a few other built-in features, but those two are probably
        the most useful.

        If you're serious about using Camlp4, you might want to read the Camlp4
        tutorial and manual. I forget where you find them, but they're certainly
        listed in the Humps. I have to say that I found the tutorial a bit tough
        to grasp: it seemed to address a number of different features in a
        number of different usage scenarios, and didn't explain very well how
        you might use all the pieces in a real application. Nonetheless, that's
        about the best documentation available.

        Hope that helps.

        --
        Matt Gushee When a nation follows the Way,
        Englewood, Colorado, USA Horses bear manure through
        mgushee@... its fields;
        http://www.havenrock.com/ When a nation ignores the Way,
        Horses bear soldiers through
        its streets.

        --Lao Tzu (Peter Merel, trans.)
      • Rahul Siddharthan
        ... Exactly what did you do? ... Perhaps you do use them and don t know it. Most list commands are part of the List module. Nothing special is need to use
        Message 3 of 9 , Jul 6, 2004
        View Source
        • 0 Attachment
          Andy Yang said on Jul 6, 2004 at 17:55:27:
          > When I tried to use "list" command in ocaml debug, I
          > was told "Not in a module".

          Exactly what did you do?

          > Actually I wrote some very
          > simple code, and do not use modules.

          Perhaps you do use them and don't know it. Most list commands are
          part of the "List" module. Nothing special is need to use them, you
          can use List.iter etc without any special includes or linking etc.

          > How shall I set
          > break points and list the programs?

          "List the programs" -- are you thinking of early Basic interpreters?
          The program is listed in your editor. (Even if you use the
          interactive toploop, it's better to write the program and
          cut-and-paste from there, or run the toploop through emacs). You
          debug it in the debugger. The line numbers the debugger gives you
          correspond to the line numbers in the source file -- it's quite
          similar to gdb.

          The manual explains the debugger quite well

          R
        • Andy Yang
          I just typed severl lines of code. For example let x = 1 let y = 2 let cmp a b = if a
          Message 4 of 9 , Jul 6, 2004
          View Source
          • 0 Attachment
            I just typed severl lines of code. For example

            let x = 1

            let y = 2

            let cmp a b = if a < b then -1 else 0

            let result = cmp x y


            Assume the above file is f1.ml. Then I compiled with
            ocamlc -g -o f1.exe f1.ml

            Then I typed
            ocamldebug f1.ml

            However, when I typed "break", "break cmp", "list",
            "list f1.ml", etc, I was told "Not in a module". Can
            simple codes like this be debugged?

            Thanks.

            Andy


            --- Rahul Siddharthan <Rsidd@...> wrote:
            > Andy Yang said on Jul 6, 2004 at 17:55:27:
            > > When I tried to use "list" command in ocaml debug,
            > I
            > > was told "Not in a module".
            >
            > Exactly what did you do?
            >
            > > Actually I wrote some very
            > > simple code, and do not use modules.
            >
            > Perhaps you do use them and don't know it. Most
            > list commands are
            > part of the "List" module. Nothing special is need
            > to use them, you
            > can use List.iter etc without any special includes
            > or linking etc.
            >
            > > How shall I set
            > > break points and list the programs?
            >
            > "List the programs" -- are you thinking of early
            > Basic interpreters?
            > The program is listed in your editor. (Even if you
            > use the
            > interactive toploop, it's better to write the
            > program and
            > cut-and-paste from there, or run the toploop through
            > emacs). You
            > debug it in the debugger. The line numbers the
            > debugger gives you
            > correspond to the line numbers in the source file --
            > it's quite
            > similar to gdb.
            >
            > The manual explains the debugger quite well
            >
            > R
            >




            __________________________________
            Do you Yahoo!?
            Yahoo! Mail - 50x more storage than other providers!
            http://promotions.yahoo.com/new_mail
          • Rahul Siddharthan
            ... I assume you mean ocamldebug f1.exe ... Ah ok. Well, your file (f1) is the module . The syntax for break in a line of source code is break @ module
            Message 5 of 9 , Jul 6, 2004
            View Source
            • 0 Attachment
              Andy Yang said on Jul 6, 2004 at 18:44:46:
              > I just typed severl lines of code. For example
              > let x = 1
              > let y = 2
              > let cmp a b = if a < b then -1 else 0
              > let result = cmp x y
              >
              > Assume the above file is f1.ml. Then I compiled with
              > ocamlc -g -o f1.exe f1.ml
              >
              > Then I typed
              > ocamldebug f1.ml

              I assume you mean ocamldebug f1.exe

              > However, when I typed "break", "break cmp", "list",
              > "list f1.ml", etc, I was told "Not in a module". Can
              > simple codes like this be debugged?

              Ah ok. Well, your file (f1) is the "module". The syntax for
              "break" in a line of source code is break @ module linenum, so try
              break @ f1 3
              (to break at line 3)

              list only works when you're running the program and are stopped (at a
              breakpoint say). So after setting the above breakpoint, if you run the
              program and then type "list" when it's stopped it will work.

              R
            Your message has been successfully submitted and would be delivered to recipients shortly.