Debugging advice required for Rust newbie


I’ve recently started programming with Rust. Seems like an interesting language.

Just not sure how to properly debug code, the compilers output isn’t descriptive enough.

I get the following error from the compiler:

thread ‘’ panicked at ‘arithmetic operation overflowed’, /home/arno/.cargo/git/checkouts/rust-mysql-simple-872ca65c96646431/master/src/
Process didn’t exit successfully: target/debug/mysql-simple (exit code: 101)

source code:

extern crate mysql;
extern crate time;

use time::Timespec;
use std::num::Float;
use mysql::conn::{MyOpts};
use mysql::conn::pool::{MyPool};
use mysql::value::{from_value};
use std::default::{Default};
use std::f32;

struct payment {
  customer_id : i32

fn main()
	let opts = MyOpts{
			user: Some("mysqluser".to_string()), 
			pass: Some("mysqluser".to_string()), 
			db_name: Some("dbsales".to_string()), 
			tcp_addr: Some("".to_string()),
	let pool = MyPool::new(opts).unwrap();

        let mut stmt = pool.prepare(
            "SELECT customer_id

	for row in stmt.execute(&[]) {
		let row = row.unwrap();
		let c = payment {
			customer_id : from_value(&row[0])
		println!("{}" , c.customer_id);

How could i get detailed information on the cause of compile error?


It seems as though its a memory overflow.

There are 35101 rows from the table. SELECT count(*) from payment. If i change the query to:
SELECT customer_id from payment LIMIT 0,10

The compiler error disappears.


Is the error emitted by the compiler as it compiles, or by your application when it runs? Could you paste the full command and output you’re using to compile/run the application?


In general:

  • look on line 175 of in rust-mysql-simple ;p


  • try gdb (breaking on rust_panic)


Just after compiling, after the program outputs the results with the command cargo run.

Output from stacktrace:

thread '<main>' panicked at 'arithmetic operation overflowed', /home/arno/.cargo/git/checkouts/rust-mysql-simple-872ca65c96646431/master/src/
stack backtrace:
   1:     0x7fda4daea082 - sys::backtrace::write::ha5fccaea9fcab689PBA
   2:     0x7fda4daef7b2 - panicking::on_panic::h0e352bd1ac18c741iHJ
   3:     0x7fda4daddcf9 - rt::unwind::begin_unwind_inner::h08ad75a305608048lnJ
   4:     0x7fda4dade0a1 - rt::unwind::begin_unwind_fmt::hc94ca365b27c6f1fWlJ
   5:     0x7fda4daef0d7 - rust_begin_unwind
   6:     0x7fda4db1b9f4 - panicking::panic_fmt::h8bc4e151698a6d25HZs
   7:     0x7fda4db1b15d - panicking::panic::h5f34a8b4b06c830dTXs
   8:     0x7fda4da9ff99 - io::Read::read_packet::h8732576705023399863
                        at /home/arno/.cargo/git/checkouts/rust-mysql-simple-872ca65c96646431/master/src/
   9:     0x7fda4da98275 - conn::MyConn::read_packet::he3c8624be2d6f721F3v
                        at /home/arno/.cargo/git/checkouts/rust-mysql-simple-872ca65c96646431/master/src/conn/
  10:     0x7fda4daae696 - conn::MyConn::next_bin::he1ee00d97e838a0brTw
                        at /home/arno/.cargo/git/checkouts/rust-mysql-simple-872ca65c96646431/master/src/conn/
  11:     0x7fda4daaff1a - conn::QueryResult<'a>.Iterator::next::h65721d8b0d44b2a5y4w
                        at /home/arno/.cargo/git/checkouts/rust-mysql-simple-872ca65c96646431/master/src/conn/
  12:     0x7fda4daae192 - conn::MyResult<QueryResult<'a>>.Iterator::next::h409395d796e205f4m7w
                        at /home/arno/.cargo/git/checkouts/rust-mysql-simple-872ca65c96646431/master/src/conn/
  13:     0x7fda4da43331 - main::hf1078ce30f2545d2uaa
                        at src/
  14:     0x7fda4daf3a88 - rust_try_inner
  15:     0x7fda4daf3a75 - rust_try
  16:     0x7fda4daf0f00 - rt::lang_start::h94ba55cffd0e1e7ayBJ
  17:     0x7fda4da43854 - main
  18:     0x7fda4cc2eec4 - __libc_start_main
  19:     0x7fda4da42d98 - <unknown>
  20:                0x0 - <unknown>

An unknown error occurred


Ah, ok: in this case this isn’t a “compile error”, so much as an error that occurs in the compiled program, at runtime. cargo run will first compile the program (the same as cargo build) and then run it if compilation succeeded (which I assume it did, in this case).

It does sound like rust-mysql-simple may have an internal bug. The looking at the relevant line, it’s not obvious why the number is overflowing. But… one might start debugging by running the program ./target/debug/mysql-simple in a debugger like GDB or LLDB. One could also just use tried and true “printf” debugging: make a local checkout of that repo, use paths to point to the override and then insert println! or use the macros from log (with env_logger)


Thank you for the great answer, much appreciated. I’ll experiment with the gdb debugger.


It was quite obvious rust-mysql-simple bug (well… by now, not when it was written :).
Anyway, it will be fixed in a few days with a bunch of other cleanups.

Feel free to file an issue next time, it’s priceless!


I’ll remember that. Any guidelines for submitting bug reports?


Not realy… There was only 6 issues reported since it’s creation, so i think i will find time to patienly handle even “IT DOES NOT WORK!!1”.