Git Product home page Git Product logo

Comments (5)

darcamo avatar darcamo commented on June 12, 2024 1

The f"some text {something}" is not a typo. It's a Python 3 f-string, which is only available since python 3.6. It is equivalent to "some text {0}".format(something). That is, whatever is inside {} will be run by Python to get the value (it can be a variable name, an expression, etc). The python version your gdb is using is prior to python 3.6 and thus you get the error.

The second error is in line 19 in gdb_armadillo_printers.py, with the super() call. More specifically, the TypeError: super() takes at least 1 argument (0 given) error. Calling supper with zero arguments is supported since python 3. Therefore, your gdb is definitely using python 2.

In order to fix this so that you can use the helpers, change the f-strings as I mentioned before. For the super calls, change super() to super(CLASS_NAME, self), where CLASS_NAME is the name of the class where the super() call happens. Ex: in the ShowArmaContentParameter class __init__ method, change super() to super(ShowArmaContentParameter, self).

These are the only changes you need to do to make it work with a gdb that is using python 2.


Note: In case of f-strings with multiple curly brackets, just use numbers as (line 119 in gdb_armadillo_printers.py)
f"{self.val.type}({self.n_rows},{self.n_cols})" should be changed to "{0}({1},{2})".format(self.val.type, self.n_rows, self.n_cols)

from gdb_armadillo_helpers.

darcamo avatar darcamo commented on June 12, 2024 1

Ah, this new error is due to the fact the python 2 had the concept of "old-style" and "new-style" classes and super can only be used in "new-style" classes. What that means is that a base class must inherit from object (that is what indicates that they are "new-style" classes).

Try changing class ArmaPrettyPrinterBase: to class ArmaPrettyPrinterBase(object):.

If you get the error in the super call in ShowArmaContentParameter (I don't know if gdb.Parameter inherits from object), then change super().__init__(...) in the ShowArmaContentParameter.__init__ method to gdb.Parameter(self).__init__(...).


Unfortunately, I don't have a way right now to try the code with a gdb version that is using python 2 and thus the best I can do is explain the errors such that you can try to fix them.

from gdb_armadillo_helpers.

bkaangorur avatar bkaangorur commented on June 12, 2024

Thank you very much for the detailed answer. I checked Python version that gdb uses. As you have said, it is Python 2.7.9.

I tried all the things that you mentioned. Unfortunately, it did not work. Now, I can start gdb without any errors, but I am getting the following errors while printing an arma::matrix

`Thread 1 hit Breakpoint 1, main (argc=1, argv=0x1101850) at ..\src\Main.cpp:23
23 cout << "Armadillo version: " << arma_version::as_string() << endl;

(gdb) n
Armadillo version: 9.800.3 (Horizon Scraper)
28 mat A(2, 3); // directly specify the matrix size (elements are uninitialised)

(gdb) n
29 A.fill(0.5);

(gdb) p A
$1 = Python Exception <type 'exceptions.TypeError'> must be type, not classobj:
Python Exception <type 'exceptions.TypeError'> must be type, not classobj:
{<arma::Base<double, arma::Mat >> = {<arma::Base_extra_yes<double, arma::Mat >> = {}, <arma::Base_eval_Mat<double, arma::Mat >> = {}, <arma::Base_trans_default<arma::Mat >> = {}, }, n_rows = 2, n_cols = 3, n_elem = 6, vec_state = 0, mem_state = 0,
mem = 0x76eea0, mem_local = {0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0, 0, 1.2648080533535912e-321, 9.3872472709836843e-323,
0, 0, 9.3872472709836843e-323, 1.9077758507644686e-315, 4.306786044898813e-317, 6.9521374683024123e-310},
static is_col = false, static is_row = false, static is_xvec = false}`

from gdb_armadillo_helpers.

bkaangorur avatar bkaangorur commented on June 12, 2024

I applied all the changes as you have explained. As is, I could run gdb and pretty printers worked well. However, I had to modify some parts, because gdb_armadillo_printers.py causes some serious performance problems. Actually, this issue appeared when I want to use it in an IDE (It is Eclipse in my case). When I started the debugger, Eclipse shows all the variables in the current scope. Since dimensions of some matrices was not assigned until the debugger comes to the specified breakpoints, they are recognized as some meaningless numbers by C++. If these numbers are too big, Eclipse starts to consume too much memory. For example, Eclipse tries to show 4548238440x3481942498 lines in the debugger window. Actually, this is also a problem if one uses gdb in console and wants to print a matrix before its dimensions are not initialized.

I overcame the problems above by making some changes that I try to explain below.

  1. Firstly, I added an "is_created()" function to ArmaPrettyPrinterBase class as following:
def is_created(self):
    if self.n_elem == self.n_rows*self.n_cols and self.n_rows != 0 and self.n_cols != 0 and self.n_elem != 0:
        return True
    return False
  1. And, I modified children() function of the same class as following:
def children(self):
    if arma_show_content.value and self.is_created():
        return self.next_element()
    return []
  1. These changes are compatible with Cube data structures since a Cube has three dimensions, including rows, cols and slices. So, it also needs an "is_created" function as following:
def is_created(self):
    if self.n_elem == self.n_rows*self.n_cols*self.n_slices and self.n_rows != 0 and self.n_cols != 0 and self.n_slices != 0 and self.n_elem != 0:
        return True
    return False
  1. After all, there was a problem with n_elem attribute of a Cube in ArmaCubePrinter. Although n_elem has been already assigned in the parent class, the n_elem value cannot be fetched correctly (I don't know why). Therefore, I added the following line at the end of the __init__ function in ArmaCubePrinter class.

self.n_elem = val['n_elem']

Now, armadillo pretty printers work very well. Thank you very much for your help.

from gdb_armadillo_helpers.

darcamo avatar darcamo commented on June 12, 2024

That is great. I'm glad it worked.

The changes you made make sense and I didn't implement these things (checking if the variable was initialized before printing) because they were not a problem for me. I work in gdb console most of the time. If you want to make of these changes into a pull request I will gladly accept it.

I'm closing the issue.

from gdb_armadillo_helpers.

Related Issues (4)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.